manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 17 | //Package adaptercore provides the utility for olt devices, flows and statistics |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 18 | package adaptercore |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "crypto/md5" |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 23 | "encoding/hex" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 24 | "encoding/json" |
| 25 | "errors" |
| 26 | "fmt" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 27 | "math/big" |
William Kurkian | 740a09c | 2019-10-23 17:07:38 -0400 | [diff] [blame] | 28 | "sync" |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 29 | "time" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 30 | |
Scott Baker | 5129015 | 2019-10-24 14:23:20 -0700 | [diff] [blame] | 31 | "github.com/opencord/voltha-lib-go/v2/pkg/flows" |
| 32 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
| 33 | tp "github.com/opencord/voltha-lib-go/v2/pkg/techprofile" |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 34 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager" |
Scott Baker | c6e54cb | 2019-11-04 09:31:25 -0800 | [diff] [blame] | 35 | "github.com/opencord/voltha-protos/v2/go/common" |
| 36 | ic "github.com/opencord/voltha-protos/v2/go/inter_container" |
| 37 | ofp "github.com/opencord/voltha-protos/v2/go/openflow_13" |
| 38 | openoltpb2 "github.com/opencord/voltha-protos/v2/go/openolt" |
| 39 | tp_pb "github.com/opencord/voltha-protos/v2/go/tech_profile" |
| 40 | "github.com/opencord/voltha-protos/v2/go/voltha" |
Chaitrashree G S | 579fe73 | 2019-08-20 20:50:47 -0400 | [diff] [blame] | 41 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 42 | //deepcopy "github.com/getlantern/deepcopy" |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 43 | "github.com/EagleChen/mapmutex" |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 44 | "google.golang.org/grpc/codes" |
| 45 | "google.golang.org/grpc/status" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 46 | ) |
| 47 | |
| 48 | const ( |
| 49 | // Flow categories |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 50 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 51 | //HsiaFlow flow category |
| 52 | HsiaFlow = "HSIA_FLOW" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 53 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 54 | //EapolFlow flow category |
| 55 | EapolFlow = "EAPOL_FLOW" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 56 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 57 | //DhcpFlow flow category |
| 58 | DhcpFlow = "DHCP_FLOW" |
| 59 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 60 | //IPProtoDhcp flow category |
| 61 | IPProtoDhcp = 17 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 62 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 63 | //IPProtoIgmp flow category |
| 64 | IPProtoIgmp = 2 |
| 65 | |
| 66 | //EapEthType eapethtype value |
| 67 | EapEthType = 0x888e |
| 68 | //LldpEthType lldp ethtype value |
| 69 | LldpEthType = 0x88cc |
| 70 | |
| 71 | //IgmpProto proto value |
| 72 | IgmpProto = 2 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 73 | |
| 74 | //FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 75 | |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 76 | //ReservedVlan Transparent Vlan |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 77 | ReservedVlan = 4095 |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 78 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 79 | //DefaultMgmtVlan default vlan value |
| 80 | DefaultMgmtVlan = 4091 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 81 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 82 | // Openolt Flow |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 83 | |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 84 | //Upstream constant |
| 85 | Upstream = "upstream" |
| 86 | //Downstream constant |
| 87 | Downstream = "downstream" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 88 | //PacketTagType constant |
| 89 | PacketTagType = "pkt_tag_type" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 90 | //Untagged constant |
| 91 | Untagged = "untagged" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 92 | //SingleTag constant |
| 93 | SingleTag = "single_tag" |
| 94 | //DoubleTag constant |
| 95 | DoubleTag = "double_tag" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 96 | |
| 97 | // classifierInfo |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 98 | |
| 99 | //EthType constant |
| 100 | EthType = "eth_type" |
| 101 | //TPID constant |
| 102 | TPID = "tpid" |
| 103 | //IPProto constant |
| 104 | IPProto = "ip_proto" |
| 105 | //InPort constant |
| 106 | InPort = "in_port" |
| 107 | //VlanVid constant |
| 108 | VlanVid = "vlan_vid" |
| 109 | //VlanPcp constant |
| 110 | VlanPcp = "vlan_pcp" |
| 111 | |
| 112 | //UDPDst constant |
| 113 | UDPDst = "udp_dst" |
| 114 | //UDPSrc constant |
| 115 | UDPSrc = "udp_src" |
| 116 | //Ipv4Dst constant |
| 117 | Ipv4Dst = "ipv4_dst" |
| 118 | //Ipv4Src constant |
| 119 | Ipv4Src = "ipv4_src" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 120 | //Metadata constant |
| 121 | Metadata = "metadata" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 122 | //TunnelID constant |
| 123 | TunnelID = "tunnel_id" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 124 | //Output constant |
| 125 | Output = "output" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 126 | // Actions |
| 127 | |
| 128 | //PopVlan constant |
| 129 | PopVlan = "pop_vlan" |
| 130 | //PushVlan constant |
| 131 | PushVlan = "push_vlan" |
| 132 | //TrapToHost constant |
| 133 | TrapToHost = "trap_to_host" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 134 | //MaxMeterBand constant |
| 135 | MaxMeterBand = 2 |
| 136 | //VlanPCPMask contant |
| 137 | VlanPCPMask = 0xFF |
| 138 | //VlanvIDMask constant |
| 139 | VlanvIDMask = 0xFFF |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 140 | //IntfID constant |
| 141 | IntfID = "intfId" |
| 142 | //OnuID constant |
| 143 | OnuID = "onuId" |
| 144 | //UniID constant |
| 145 | UniID = "uniId" |
| 146 | //PortNo constant |
| 147 | PortNo = "portNo" |
| 148 | //AllocID constant |
| 149 | AllocID = "allocId" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 150 | ) |
| 151 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 152 | type gemPortKey struct { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 153 | intfID uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 154 | gemPort uint32 |
| 155 | } |
| 156 | |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 157 | type pendingFlowDeleteKey struct { |
| 158 | intfID uint32 |
| 159 | onuID uint32 |
| 160 | uniID uint32 |
| 161 | } |
| 162 | |
| 163 | type tpLockKey struct { |
| 164 | intfID uint32 |
| 165 | onuID uint32 |
| 166 | uniID uint32 |
| 167 | } |
| 168 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 169 | type schedQueue struct { |
| 170 | direction tp_pb.Direction |
| 171 | intfID uint32 |
| 172 | onuID uint32 |
| 173 | uniID uint32 |
| 174 | tpID uint32 |
| 175 | uniPort uint32 |
| 176 | tpInst *tp.TechProfile |
| 177 | meterID uint32 |
| 178 | flowMetadata *voltha.FlowMetadata |
| 179 | } |
| 180 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 181 | //OpenOltFlowMgr creates the Structure of OpenOltFlowMgr obj |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 182 | type OpenOltFlowMgr struct { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 183 | techprofile map[uint32]tp.TechProfileIf |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 184 | deviceHandler *DeviceHandler |
| 185 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 186 | onuIdsLock sync.RWMutex |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 187 | flowsUsedByGemPort map[gemPortKey][]uint32 //gem port id to flow ids |
| 188 | packetInGemPort map[rsrcMgr.PacketInInfoKey]uint32 //packet in gem port local cache |
| 189 | onuGemInfo map[uint32][]rsrcMgr.OnuGemInfo //onu, gem and uni info local cache |
| 190 | lockCache sync.RWMutex |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 191 | pendingFlowDelete sync.Map |
| 192 | // The mapmutex.Mutex can be fine tuned to use mapmutex.NewCustomizedMapMutex |
| 193 | perUserFlowHandleLock *mapmutex.Mutex |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 194 | } |
| 195 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 196 | //NewFlowManager creates OpenOltFlowMgr object and initializes the parameters |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 197 | func NewFlowManager(dh *DeviceHandler, rMgr *rsrcMgr.OpenOltResourceMgr) *OpenOltFlowMgr { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 198 | log.Info("Initializing flow manager") |
| 199 | var flowMgr OpenOltFlowMgr |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 200 | var err error |
| 201 | var idx uint32 |
| 202 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 203 | flowMgr.deviceHandler = dh |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 204 | flowMgr.resourceMgr = rMgr |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 205 | flowMgr.techprofile = make(map[uint32]tp.TechProfileIf) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 206 | if err = flowMgr.populateTechProfilePerPonPort(); err != nil { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 207 | log.Error("Error while populating tech profile mgr\n") |
| 208 | return nil |
| 209 | } |
William Kurkian | 740a09c | 2019-10-23 17:07:38 -0400 | [diff] [blame] | 210 | flowMgr.onuIdsLock = sync.RWMutex{} |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 211 | flowMgr.flowsUsedByGemPort = make(map[gemPortKey][]uint32) |
| 212 | flowMgr.packetInGemPort = make(map[rsrcMgr.PacketInInfoKey]uint32) |
| 213 | flowMgr.onuGemInfo = make(map[uint32][]rsrcMgr.OnuGemInfo) |
| 214 | ponPorts := rMgr.DevInfo.GetPonPorts() |
| 215 | //Load the onugem info cache from kv store on flowmanager start |
| 216 | for idx = 0; idx < ponPorts; idx++ { |
| 217 | if flowMgr.onuGemInfo[idx], err = rMgr.GetOnuGemInfo(idx); err != nil { |
| 218 | log.Error("Failed to load onu gem info cache") |
| 219 | } |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 220 | //Load flowID list per gem map per interface from the kvstore. |
| 221 | flowMgr.loadFlowIDlistForGem(idx) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 222 | } |
| 223 | flowMgr.lockCache = sync.RWMutex{} |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 224 | flowMgr.pendingFlowDelete = sync.Map{} |
| 225 | flowMgr.perUserFlowHandleLock = mapmutex.NewMapMutex() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 226 | log.Info("Initialization of flow manager success!!") |
| 227 | return &flowMgr |
| 228 | } |
| 229 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 230 | func (f *OpenOltFlowMgr) generateStoredFlowID(flowID uint32, direction string) (uint64, error) { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 231 | if direction == Upstream { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 232 | log.Debug("upstream flow, shifting id") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 233 | return 0x1<<15 | uint64(flowID), nil |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 234 | } else if direction == Downstream { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 235 | log.Debug("downstream flow, not shifting id") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 236 | return uint64(flowID), nil |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 237 | } else { |
| 238 | log.Debug("Unrecognized direction") |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 239 | return 0, fmt.Errorf("unrecognized direction %s", direction) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 243 | func (f *OpenOltFlowMgr) registerFlow(flowFromCore *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 244 | log.Debug("Registering Flow for Device ", log.Fields{"flow": flowFromCore}, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 245 | log.Fields{"device": f.deviceHandler.deviceID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 246 | gemPK := gemPortKey{uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId)} |
| 247 | flowIDList, ok := f.flowsUsedByGemPort[gemPK] |
| 248 | if !ok { |
| 249 | flowIDList = []uint32{deviceFlow.FlowId} |
| 250 | } |
| 251 | flowIDList = appendUnique(flowIDList, deviceFlow.FlowId) |
| 252 | f.flowsUsedByGemPort[gemPK] = flowIDList |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 253 | // update the flowids for a gem to the KVstore |
| 254 | f.resourceMgr.UpdateFlowIDsForGem(uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId), flowIDList) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 255 | } |
| 256 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 257 | func (f *OpenOltFlowMgr) divideAndAddFlow(intfID uint32, onuID uint32, uniID uint32, portNo uint32, |
| 258 | classifierInfo map[string]interface{}, actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpID uint32, |
| 259 | UsMeterID uint32, DsMeterID uint32, flowMetadata *voltha.FlowMetadata) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 260 | var allocID uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 261 | var gemPorts []uint32 |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 262 | var TpInst *tp.TechProfile |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 263 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 264 | 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] | 265 | "classifier": classifierInfo, "action": actionInfo, "UsMeterID": UsMeterID, "DsMeterID": DsMeterID, "TpID": TpID}) |
Matt Jeanneret | 7719961 | 2019-07-26 18:08:35 -0400 | [diff] [blame] | 266 | // only create tcont/gemports if there is actually an onu id. otherwise BAL throws an error. Usually this |
| 267 | // is because the flow is an NNI flow and there would be no onu resources associated with it |
| 268 | // TODO: properly deal with NNI flows |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 269 | if onuID <= 0 { |
Matt Jeanneret | 7719961 | 2019-07-26 18:08:35 -0400 | [diff] [blame] | 270 | 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] | 271 | return |
| 272 | } |
| 273 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 274 | uni := getUniPortPath(intfID, int32(onuID), int32(uniID)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 275 | log.Debugw("Uni port name", log.Fields{"uni": uni}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 276 | |
| 277 | tpLockMapKey := tpLockKey{intfID, onuID, uniID} |
| 278 | if f.perUserFlowHandleLock.TryLock(tpLockMapKey) { |
| 279 | allocID, gemPorts, TpInst = f.createTcontGemports(intfID, onuID, uniID, uni, portNo, TpID, UsMeterID, DsMeterID, flowMetadata) |
| 280 | if allocID == 0 || gemPorts == nil || TpInst == nil { |
| 281 | log.Error("alloc-id-gem-ports-tp-unavailable") |
| 282 | f.perUserFlowHandleLock.Unlock(tpLockMapKey) |
| 283 | return |
| 284 | } |
| 285 | args := make(map[string]uint32) |
| 286 | args[IntfID] = intfID |
| 287 | args[OnuID] = onuID |
| 288 | args[UniID] = uniID |
| 289 | args[PortNo] = portNo |
| 290 | args[AllocID] = allocID |
| 291 | |
| 292 | /* Flows can be added specific to gemport if p-bits are received. |
| 293 | * If no pbit mentioned then adding flows for all gemports |
| 294 | */ |
| 295 | f.checkAndAddFlow(args, classifierInfo, actionInfo, flow, TpInst, gemPorts, TpID, uni) |
| 296 | f.perUserFlowHandleLock.Unlock(tpLockMapKey) |
| 297 | } else { |
| 298 | log.Errorw("failed to acquire per user flow handle lock", |
| 299 | log.Fields{"intfId": intfID, "onuId": onuID, "uniId": uniID}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 300 | return |
| 301 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 302 | } |
| 303 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 304 | // CreateSchedulerQueues creates traffic schedulers on the device with the given scheduler configuration and traffic shaping info |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 305 | func (f *OpenOltFlowMgr) CreateSchedulerQueues(sq schedQueue) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 306 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 307 | log.Debugw("CreateSchedulerQueues", log.Fields{"Dir": sq.direction, "IntfID": sq.intfID, |
| 308 | "OnuID": sq.onuID, "UniID": sq.uniID, "TpID": sq.tpID, "MeterID": sq.meterID, |
| 309 | "TpInst": sq.tpInst, "flowMetadata": sq.flowMetadata}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 310 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 311 | Direction, err := verifyMeterIDAndGetDirection(sq.meterID, sq.direction) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 312 | if err != nil { |
| 313 | return err |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /* Lets make a simple assumption that if the meter-id is present on the KV store, |
| 317 | * then the scheduler and queues configuration is applied on the OLT device |
| 318 | * in the given direction. |
| 319 | */ |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 320 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 321 | var SchedCfg *tp_pb.SchedulerConfig |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 322 | KvStoreMeter, err := f.resourceMgr.GetMeterIDForOnu(Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 323 | if err != nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 324 | 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] | 325 | return err |
| 326 | } |
| 327 | if KvStoreMeter != nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 328 | if KvStoreMeter.MeterId == sq.meterID { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 329 | log.Debug("Scheduler already created for upstream") |
| 330 | return nil |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 331 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 332 | log.Errorw("Dynamic meter update not supported", log.Fields{"KvStoreMeterId": KvStoreMeter.MeterId, "MeterID-in-flow": sq.meterID}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 333 | return errors.New("invalid-meter-id-in-flow") |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 334 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 335 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 336 | 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] | 337 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 338 | if sq.direction == tp_pb.Direction_UPSTREAM { |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 339 | SchedCfg, err = f.techprofile[sq.intfID].GetUsScheduler(sq.tpInst) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 340 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 341 | SchedCfg, err = f.techprofile[sq.intfID].GetDsScheduler(sq.tpInst) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 342 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 343 | |
| 344 | if err != nil { |
| 345 | log.Errorw("Unable to get Scheduler config", log.Fields{"IntfID": sq.intfID, "Direction": sq.direction, "Error": err}) |
| 346 | return err |
| 347 | } |
| 348 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 349 | var meterConfig *ofp.OfpMeterConfig |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 350 | if sq.flowMetadata != nil { |
| 351 | for _, meter := range sq.flowMetadata.Meters { |
| 352 | if sq.meterID == meter.MeterId { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 353 | meterConfig = meter |
| 354 | log.Debugw("Found-meter-config-from-flowmetadata", log.Fields{"meterConfig": meterConfig}) |
| 355 | break |
| 356 | } |
| 357 | } |
| 358 | } else { |
| 359 | log.Error("Flow-metadata-is-not-present-in-flow") |
| 360 | } |
| 361 | if meterConfig == nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 362 | log.Errorw("Could-not-get-meterbands-from-flowMetadata", log.Fields{"flowMetadata": sq.flowMetadata, |
| 363 | "MeterID": sq.meterID}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 364 | return errors.New("failed-to-get-meter-from-flowMetadata") |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 365 | } else if len(meterConfig.Bands) < MaxMeterBand { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 366 | log.Errorw("Invalid-number-of-bands-in-meter", log.Fields{"Bands": meterConfig.Bands, "MeterID": sq.meterID}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 367 | return errors.New("invalid-number-of-bands-in-meter") |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 368 | } |
| 369 | cir := meterConfig.Bands[0].Rate |
| 370 | cbs := meterConfig.Bands[0].BurstSize |
| 371 | eir := meterConfig.Bands[1].Rate |
| 372 | ebs := meterConfig.Bands[1].BurstSize |
| 373 | pir := cir + eir |
| 374 | pbs := cbs + ebs |
| 375 | TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: cir, Cbs: cbs, Pir: pir, Pbs: pbs} |
| 376 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 377 | 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] | 378 | |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 379 | if err := f.pushSchedulerQueuesToDevice(sq, TrafficShaping, TrafficSched); err != nil { |
| 380 | 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] | 381 | return err |
| 382 | } |
| 383 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 384 | /* After we successfully applied the scheduler configuration on the OLT device, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 385 | * store the meter id on the KV store, for further reference. |
| 386 | */ |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 387 | if err := f.resourceMgr.UpdateMeterIDForOnu(Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID, meterConfig); err != nil { |
| 388 | 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] | 389 | return err |
| 390 | } |
| 391 | log.Debugw("updated-meter-info into KV store successfully", log.Fields{"Direction": Direction, |
| 392 | "Meter": meterConfig}) |
| 393 | return nil |
| 394 | } |
| 395 | |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 396 | func (f *OpenOltFlowMgr) pushSchedulerQueuesToDevice(sq schedQueue, TrafficShaping *tp_pb.TrafficShapingInfo, TrafficSched []*tp_pb.TrafficScheduler) error { |
| 397 | |
| 398 | trafficQueues, err := f.techprofile[sq.intfID].GetTrafficQueues(sq.tpInst, sq.direction) |
| 399 | |
| 400 | if err != nil { |
| 401 | log.Errorw("Unable to construct traffic queue configuration", log.Fields{"intfID": sq.intfID, "direction": sq.direction}) |
| 402 | return err |
| 403 | } |
| 404 | |
| 405 | log.Debugw("Sending Traffic scheduler create to device", log.Fields{"Direction": sq.direction, "TrafficScheds": TrafficSched}) |
| 406 | if _, err := f.deviceHandler.Client.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{ |
| 407 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 408 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 409 | TrafficScheds: TrafficSched}); err != nil { |
| 410 | log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err}) |
| 411 | return err |
| 412 | } |
| 413 | |
| 414 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 415 | // downstream queues. |
| 416 | log.Debugw("Sending Traffic Queues create to device", log.Fields{"Direction": sq.direction, "TrafficQueues": trafficQueues}) |
| 417 | if _, err := f.deviceHandler.Client.CreateTrafficQueues(context.Background(), |
| 418 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 419 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 420 | TrafficQueues: trafficQueues}); err != nil { |
| 421 | log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err}) |
| 422 | return err |
| 423 | } |
| 424 | |
| 425 | return nil |
| 426 | } |
| 427 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 428 | // RemoveSchedulerQueues removes the traffic schedulers from the device based on the given scheduler configuration and traffic shaping info |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 429 | func (f *OpenOltFlowMgr) RemoveSchedulerQueues(sq schedQueue) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 430 | |
| 431 | var Direction string |
| 432 | var SchedCfg *tp_pb.SchedulerConfig |
| 433 | var err error |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 434 | log.Debugw("Removing schedulers and Queues in OLT", log.Fields{"Direction": sq.direction, "IntfID": sq.intfID, |
| 435 | "OnuID": sq.onuID, "UniID": sq.uniID, "UniPort": sq.uniPort}) |
| 436 | if sq.direction == tp_pb.Direction_UPSTREAM { |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 437 | SchedCfg, err = f.techprofile[sq.intfID].GetUsScheduler(sq.tpInst) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 438 | Direction = "upstream" |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 439 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 440 | SchedCfg, err = f.techprofile[sq.intfID].GetDsScheduler(sq.tpInst) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 441 | Direction = "downstream" |
| 442 | } |
| 443 | |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 444 | if err != nil { |
| 445 | log.Errorw("Unable to get Scheduler config", log.Fields{"IntID": sq.intfID, "Direction": sq.direction, "Error": err}) |
| 446 | return err |
| 447 | } |
| 448 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 449 | KVStoreMeter, err := f.resourceMgr.GetMeterIDForOnu(Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 450 | if err != nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 451 | log.Errorf("Failed to get Meter for Onu %d", sq.onuID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 452 | return err |
| 453 | } |
| 454 | if KVStoreMeter == nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 455 | 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] | 456 | return nil |
| 457 | } |
| 458 | cir := KVStoreMeter.Bands[0].Rate |
| 459 | cbs := KVStoreMeter.Bands[0].BurstSize |
| 460 | eir := KVStoreMeter.Bands[1].Rate |
| 461 | ebs := KVStoreMeter.Bands[1].BurstSize |
| 462 | pir := cir + eir |
| 463 | pbs := cbs + ebs |
| 464 | |
| 465 | TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: cir, Cbs: cbs, Pir: pir, Pbs: pbs} |
| 466 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 467 | 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] | 468 | |
| 469 | TrafficQueues, err := f.techprofile[sq.intfID].GetTrafficQueues(sq.tpInst, sq.direction) |
| 470 | if err != nil { |
| 471 | log.Errorw("Unable to construct traffic queue configuration", log.Fields{"intfID": sq.intfID, "direction": sq.direction}) |
| 472 | return err |
| 473 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 474 | |
| 475 | if _, err = f.deviceHandler.Client.RemoveTrafficQueues(context.Background(), |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 476 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 477 | UniId: sq.uniID, PortNo: sq.uniPort, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 478 | TrafficQueues: TrafficQueues}); err != nil { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 479 | log.Errorw("Failed to remove traffic queues", log.Fields{"error": err}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 480 | return err |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 481 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 482 | log.Debug("Removed traffic queues successfully") |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 483 | if _, err = f.deviceHandler.Client.RemoveTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{ |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 484 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 485 | UniId: sq.uniID, PortNo: sq.uniPort, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 486 | TrafficScheds: TrafficSched}); err != nil { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 487 | log.Errorw("failed to remove traffic schedulers", log.Fields{"error": err}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 488 | return err |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 489 | } |
| 490 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 491 | log.Debug("Removed traffic schedulers successfully") |
| 492 | |
| 493 | /* After we successfully remove the scheduler configuration on the OLT device, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 494 | * delete the meter id on the KV store. |
| 495 | */ |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 496 | err = f.resourceMgr.RemoveMeterIDForOnu(Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 497 | if err != nil { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 498 | 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] | 499 | return err |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 500 | } |
| 501 | log.Debugw("Removed-meter-from-KV-store successfully", log.Fields{"MeterId": KVStoreMeter.MeterId, "dir": Direction}) |
| 502 | return err |
| 503 | } |
| 504 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 505 | // This function allocates tconts and GEM ports for an ONU |
| 506 | func (f *OpenOltFlowMgr) createTcontGemports(intfID uint32, onuID uint32, uniID uint32, uni string, uniPort uint32, TpID uint32, UsMeterID uint32, DsMeterID uint32, flowMetadata *voltha.FlowMetadata) (uint32, []uint32, *tp.TechProfile) { |
| 507 | var allocIDs []uint32 |
| 508 | var allgemPortIDs []uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 509 | var gemPortIDs []uint32 |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 510 | tpInstanceExists := false |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 511 | var err error |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 512 | |
| 513 | allocIDs = f.resourceMgr.GetCurrentAllocIDsForOnu(intfID, onuID, uniID) |
| 514 | allgemPortIDs = f.resourceMgr.GetCurrentGEMPortIDsForOnu(intfID, onuID, uniID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 515 | |
| 516 | tpPath := f.getTPpath(intfID, uni, TpID) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 517 | |
| 518 | log.Infow("creating-new-tcont-and-gem", log.Fields{"pon": intfID, "onu": onuID, "uni": uniID}) |
| 519 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 520 | // Check tech profile instance already exists for derived port name |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 521 | techProfileInstance, _ := f.techprofile[intfID].GetTPInstanceFromKVStore(TpID, tpPath) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 522 | if techProfileInstance == nil { |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 523 | log.Infow("tp-instance-not-found--creating-new", log.Fields{"path": tpPath}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 524 | techProfileInstance, err = f.techprofile[intfID].CreateTechProfInstance(TpID, uni, intfID) |
| 525 | if err != nil { |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 526 | // This should not happen, something wrong in KV backend transaction |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 527 | log.Errorw("tp-instance-create-failed", log.Fields{"error": err, "tpID": TpID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 528 | return 0, nil, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 529 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 530 | f.resourceMgr.UpdateTechProfileIDForOnu(intfID, onuID, uniID, TpID) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 531 | } else { |
| 532 | 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] | 533 | tpInstanceExists = true |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 534 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 535 | if UsMeterID != 0 { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 536 | sq := schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| 537 | uniPort: uniPort, tpInst: techProfileInstance, meterID: UsMeterID, flowMetadata: flowMetadata} |
| 538 | if err := f.CreateSchedulerQueues(sq); err != nil { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 539 | log.Errorw("CreateSchedulerQueues Failed-upstream", log.Fields{"error": err, "meterID": UsMeterID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 540 | return 0, nil, nil |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 541 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 542 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 543 | if DsMeterID != 0 { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 544 | sq := schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| 545 | uniPort: uniPort, tpInst: techProfileInstance, meterID: DsMeterID, flowMetadata: flowMetadata} |
| 546 | if err := f.CreateSchedulerQueues(sq); err != nil { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 547 | log.Errorw("CreateSchedulerQueues Failed-downstream", log.Fields{"error": err, "meterID": DsMeterID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 548 | return 0, nil, nil |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 549 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 550 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 551 | |
| 552 | allocID := techProfileInstance.UsScheduler.AllocID |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 553 | for _, gem := range techProfileInstance.UpstreamGemPortAttributeList { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 554 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 555 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 556 | |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 557 | if tpInstanceExists { |
| 558 | return allocID, gemPortIDs, techProfileInstance |
| 559 | } |
| 560 | |
| 561 | allocIDs = appendUnique(allocIDs, allocID) |
| 562 | for _, gemPortID := range gemPortIDs { |
| 563 | allgemPortIDs = appendUnique(allgemPortIDs, gemPortID) |
| 564 | } |
| 565 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 566 | 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] | 567 | // Send Tconts and GEM ports to KV store |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 568 | f.storeTcontsGEMPortsIntoKVStore(intfID, onuID, uniID, allocIDs, allgemPortIDs) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 569 | return allocID, gemPortIDs, techProfileInstance |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 570 | } |
| 571 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 572 | func (f *OpenOltFlowMgr) storeTcontsGEMPortsIntoKVStore(intfID uint32, onuID uint32, uniID uint32, allocID []uint32, gemPortIDs []uint32) { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 573 | |
| 574 | log.Debugw("Storing allocated Tconts and GEM ports into KV store", |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 575 | log.Fields{"intfId": intfID, "onuId": onuID, "uniId": uniID, "allocID": allocID, "gemPortIDs": gemPortIDs}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 576 | /* Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV store */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 577 | if err := f.resourceMgr.UpdateAllocIdsForOnu(intfID, onuID, uniID, allocID); err != nil { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 578 | log.Error("Errow while uploading allocID to KV store") |
| 579 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 580 | if err := f.resourceMgr.UpdateGEMPortIDsForOnu(intfID, onuID, uniID, gemPortIDs); err != nil { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 581 | log.Error("Errow while uploading GEMports to KV store") |
| 582 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 583 | if err := f.resourceMgr.UpdateGEMportsPonportToOnuMapOnKVStore(gemPortIDs, intfID, onuID, uniID); err != nil { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 584 | log.Error("Errow while uploading gemtopon map to KV store") |
| 585 | } |
| 586 | log.Debug("Stored tconts and GEM into KV store successfully") |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 587 | for _, gemPort := range gemPortIDs { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 588 | f.addGemPortToOnuInfoMap(intfID, onuID, gemPort) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 589 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | func (f *OpenOltFlowMgr) populateTechProfilePerPonPort() error { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 593 | var tpCount int |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 594 | for _, techRange := range f.resourceMgr.DevInfo.Ranges { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 595 | for _, intfID := range techRange.IntfIds { |
| 596 | f.techprofile[intfID] = f.resourceMgr.ResourceMgrs[uint32(intfID)].TechProfileMgr |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 597 | tpCount++ |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 598 | log.Debugw("Init tech profile done", log.Fields{"intfID": intfID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | //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] | 602 | if tpCount != int(f.resourceMgr.DevInfo.GetPonPorts()) { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 603 | log.Errorw("Error while populating techprofile", |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 604 | log.Fields{"numofTech": tpCount, "numPonPorts": f.resourceMgr.DevInfo.GetPonPorts()}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 605 | return errors.New("error while populating techprofile mgrs") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 606 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 607 | log.Infow("Populated techprofile for ponports successfully", |
| 608 | log.Fields{"numofTech": tpCount, "numPonPorts": f.resourceMgr.DevInfo.GetPonPorts()}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 609 | return nil |
| 610 | } |
| 611 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 612 | func (f *OpenOltFlowMgr) addUpstreamDataFlow(intfID uint32, onuID uint32, uniID uint32, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 613 | portNo uint32, uplinkClassifier map[string]interface{}, |
| 614 | uplinkAction map[string]interface{}, logicalFlow *ofp.OfpFlowStats, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 615 | allocID uint32, gemportID uint32) { |
| 616 | uplinkClassifier[PacketTagType] = SingleTag |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 617 | log.Debugw("Adding upstream data flow", log.Fields{"uplinkClassifier": uplinkClassifier, "uplinkAction": uplinkAction}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 618 | f.addHSIAFlow(intfID, onuID, uniID, portNo, uplinkClassifier, uplinkAction, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 619 | Upstream, logicalFlow, allocID, gemportID) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 620 | /* TODO: Install Secondary EAP on the subscriber vlan */ |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 621 | } |
| 622 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 623 | func (f *OpenOltFlowMgr) addDownstreamDataFlow(intfID uint32, onuID uint32, uniID uint32, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 624 | portNo uint32, downlinkClassifier map[string]interface{}, |
| 625 | downlinkAction map[string]interface{}, logicalFlow *ofp.OfpFlowStats, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 626 | allocID uint32, gemportID uint32) { |
| 627 | downlinkClassifier[PacketTagType] = DoubleTag |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 628 | log.Debugw("Adding downstream data flow", log.Fields{"downlinkClassifier": downlinkClassifier, |
| 629 | "downlinkAction": downlinkAction}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 630 | // Ignore Downlink trap flow given by core, cannot do anything with this flow */ |
| 631 | if vlan, exists := downlinkClassifier[VlanVid]; exists { |
| 632 | 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] | 633 | 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] | 634 | if uint32(metadata.(uint64)) == MkUniPortNum(intfID, onuID, uniID) { |
| 635 | log.Infow("Ignoring DL trap device flow from core", log.Fields{"flow": logicalFlow}) |
| 636 | return |
| 637 | } |
| 638 | } |
| 639 | } |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 640 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 641 | |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 642 | /* Already this info available classifier? */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 643 | downlinkAction[PopVlan] = true |
Matt Jeanneret | ed16b7c | 2019-11-01 13:31:35 -0400 | [diff] [blame] | 644 | // vlan_vid is a uint32. must be type asserted as such or conversion fails |
| 645 | dlClVid, ok := downlinkClassifier[VlanVid].(uint32) |
Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 646 | if ok { |
| 647 | downlinkAction[VlanVid] = dlClVid & 0xfff |
| 648 | } else { |
| 649 | log.Error("dl-classifier-vid-type-conversion-failed") |
| 650 | return |
| 651 | } |
| 652 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 653 | f.addHSIAFlow(intfID, onuID, uniID, portNo, downlinkClassifier, downlinkAction, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 654 | Downstream, logicalFlow, allocID, gemportID) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 655 | } |
| 656 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 657 | func (f *OpenOltFlowMgr) addHSIAFlow(intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{}, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 658 | action map[string]interface{}, direction string, logicalFlow *ofp.OfpFlowStats, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 659 | allocID uint32, gemPortID uint32) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 660 | var networkIntfID uint32 |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 661 | /* One of the OLT platform (Broadcom BAL) requires that symmetric |
| 662 | flows require the same flow_id to be used across UL and DL. |
| 663 | Since HSIA flow is the only symmetric flow currently, we need to |
| 664 | re-use the flow_id across both direction. The 'flow_category' |
| 665 | takes priority over flow_cookie to find any available HSIA_FLOW |
| 666 | id for the ONU. |
| 667 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 668 | log.Debugw("Adding HSIA flow", log.Fields{"intfId": intfID, "onuId": onuID, "uniId": uniID, "classifier": classifier, |
| 669 | "action": action, "direction": direction, "allocId": allocID, "gemPortId": gemPortID, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 670 | "logicalFlow": *logicalFlow}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 671 | var vlanPbit uint32 |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 672 | if _, ok := classifier[VlanPcp]; ok { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 673 | vlanPbit = classifier[VlanPcp].(uint32) |
| 674 | log.Debugw("Found pbit in the flow", log.Fields{"VlanPbit": vlanPbit}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 675 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 676 | flowStoreCookie := getFlowStoreCookie(classifier, gemPortID) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 677 | if present := f.resourceMgr.IsFlowCookieOnKVStore(uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
| 678 | log.Debug("Flow-exists--not-re-adding") |
| 679 | return |
| 680 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 681 | flowID, err := f.resourceMgr.GetFlowID(intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, HsiaFlow, vlanPbit) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 682 | if err != nil { |
| 683 | log.Errorw("Flow id unavailable for HSIA flow", log.Fields{"direction": direction}) |
| 684 | return |
| 685 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 686 | var classifierProto *openoltpb2.Classifier |
| 687 | var actionProto *openoltpb2.Action |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 688 | if classifierProto = makeOpenOltClassifierField(classifier); classifierProto == nil { |
| 689 | log.Error("Error in making classifier protobuf for hsia flow") |
| 690 | return |
| 691 | } |
| 692 | log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto}) |
| 693 | if actionProto = makeOpenOltActionField(action); actionProto == nil { |
| 694 | log.Errorw("Error in making action protobuf for hsia flow", log.Fields{"direction": direction}) |
| 695 | return |
| 696 | } |
| 697 | log.Debugw("Created action proto", log.Fields{"action": *actionProto}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 698 | networkIntfID, err = getNniIntfID(classifier, action) |
| 699 | if err != nil { |
| 700 | log.Error("Failed to get nniIntf ID") |
| 701 | return |
| 702 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 703 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
| 704 | OnuId: int32(onuID), |
| 705 | UniId: int32(uniID), |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 706 | FlowId: flowID, |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 707 | FlowType: direction, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 708 | AllocId: int32(allocID), |
| 709 | NetworkIntfId: int32(networkIntfID), |
| 710 | GemportId: int32(gemPortID), |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 711 | Classifier: classifierProto, |
| 712 | Action: actionProto, |
| 713 | Priority: int32(logicalFlow.Priority), |
| 714 | Cookie: logicalFlow.Cookie, |
| 715 | PortNo: portNo} |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 716 | if ok := f.addFlowToDevice(logicalFlow, &flow); ok { |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 717 | log.Debug("HSIA flow added to device successfully", log.Fields{"direction": direction}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 718 | flowsToKVStore := f.getUpdatedFlowInfo(&flow, flowStoreCookie, HsiaFlow, flowID, logicalFlow.Id) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 719 | if err := f.updateFlowInfoToKVStore(flow.AccessIntfId, |
| 720 | flow.OnuId, |
| 721 | flow.UniId, |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 722 | flow.FlowId /*flowCategory,*/, flowsToKVStore); err != nil { |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 723 | log.Errorw("Error uploading HSIA flow into KV store", log.Fields{"flow": flow, "direction": direction, "error": err}) |
| 724 | return |
| 725 | } |
| 726 | } |
| 727 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 728 | func (f *OpenOltFlowMgr) addDHCPTrapFlow(intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{}, action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, gemPortID uint32) { |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 729 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 730 | var dhcpFlow openoltpb2.Flow |
| 731 | var actionProto *openoltpb2.Action |
| 732 | var classifierProto *openoltpb2.Classifier |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 733 | var flowID uint32 |
| 734 | networkIntfID, err := getNniIntfID(classifier, action) |
| 735 | if err != nil { |
| 736 | log.Error("Failed to get nniIntf ID") |
| 737 | return |
| 738 | } |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 739 | |
| 740 | // Clear the action map |
| 741 | for k := range action { |
| 742 | delete(action, k) |
| 743 | } |
| 744 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 745 | action[TrapToHost] = true |
| 746 | classifier[UDPSrc] = uint32(68) |
| 747 | classifier[UDPDst] = uint32(67) |
| 748 | classifier[PacketTagType] = SingleTag |
| 749 | delete(classifier, VlanVid) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 750 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 751 | flowStoreCookie := getFlowStoreCookie(classifier, gemPortID) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 752 | if present := f.resourceMgr.IsFlowCookieOnKVStore(uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
| 753 | log.Debug("Flow-exists--not-re-adding") |
| 754 | return |
| 755 | } |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 756 | |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 757 | flowID, err = f.resourceMgr.GetFlowID(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] | 758 | |
| 759 | if err != nil { |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 760 | log.Errorw("flowId unavailable for UL DHCP", log.Fields{"intfId": intfID, "onuId": onuID, "flowStoreCookie": flowStoreCookie}) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 761 | return |
| 762 | } |
| 763 | |
| 764 | log.Debugw("Creating UL DHCP flow", log.Fields{"ul_classifier": classifier, "ul_action": action, "uplinkFlowId": flowID}) |
| 765 | |
| 766 | if classifierProto = makeOpenOltClassifierField(classifier); classifierProto == nil { |
| 767 | log.Error("Error in making classifier protobuf for ul flow") |
| 768 | return |
| 769 | } |
| 770 | log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto}) |
| 771 | if actionProto = makeOpenOltActionField(action); actionProto == nil { |
| 772 | log.Error("Error in making action protobuf for ul flow") |
| 773 | return |
| 774 | } |
| 775 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 776 | dhcpFlow = openoltpb2.Flow{AccessIntfId: int32(intfID), |
| 777 | OnuId: int32(onuID), |
| 778 | UniId: int32(uniID), |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 779 | FlowId: flowID, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 780 | FlowType: Upstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 781 | AllocId: int32(allocID), |
| 782 | NetworkIntfId: int32(networkIntfID), |
| 783 | GemportId: int32(gemPortID), |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 784 | Classifier: classifierProto, |
| 785 | Action: actionProto, |
| 786 | Priority: int32(logicalFlow.Priority), |
| 787 | Cookie: logicalFlow.Cookie, |
| 788 | PortNo: portNo} |
| 789 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 790 | if ok := f.addFlowToDevice(logicalFlow, &dhcpFlow); ok { |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 791 | log.Debug("DHCP UL flow added to device successfully") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 792 | flowsToKVStore := f.getUpdatedFlowInfo(&dhcpFlow, flowStoreCookie, "DHCP", flowID, logicalFlow.Id) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 793 | if err := f.updateFlowInfoToKVStore(dhcpFlow.AccessIntfId, |
| 794 | dhcpFlow.OnuId, |
| 795 | dhcpFlow.UniId, |
| 796 | dhcpFlow.FlowId, flowsToKVStore); err != nil { |
| 797 | log.Errorw("Error uploading DHCP UL flow into KV store", log.Fields{"flow": dhcpFlow, "error": err}) |
| 798 | return |
| 799 | } |
| 800 | } |
| 801 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 802 | return |
| 803 | } |
| 804 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 805 | // Add EAPOL flow to device with mac, vlanId as classifier for upstream and downstream |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 806 | func (f *OpenOltFlowMgr) addEAPOLFlow(intfID uint32, onuID uint32, uniID uint32, portNo uint32, logicalFlow *ofp.OfpFlowStats, allocID uint32, gemPortID uint32, vlanID uint32, classifier map[string]interface{}, action map[string]interface{}) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 807 | 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] | 808 | |
| 809 | uplinkClassifier := make(map[string]interface{}) |
| 810 | uplinkAction := make(map[string]interface{}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 811 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 812 | var upstreamFlow openoltpb2.Flow |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 813 | var networkIntfID uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 814 | |
| 815 | // Fill Classfier |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 816 | uplinkClassifier[EthType] = uint32(EapEthType) |
| 817 | uplinkClassifier[PacketTagType] = SingleTag |
| 818 | uplinkClassifier[VlanVid] = vlanID |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 819 | // Fill action |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 820 | uplinkAction[TrapToHost] = true |
| 821 | flowStoreCookie := getFlowStoreCookie(uplinkClassifier, gemPortID) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 822 | if present := f.resourceMgr.IsFlowCookieOnKVStore(uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present { |
| 823 | log.Debug("Flow-exists--not-re-adding") |
| 824 | return |
| 825 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 826 | //Add Uplink EAPOL Flow |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 827 | uplinkFlowID, err := f.resourceMgr.GetFlowID(intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, "", 0) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 828 | if err != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 829 | log.Errorw("flowId unavailable for UL EAPOL", log.Fields{"intfId": intfID, "onuId": onuID, "flowStoreCookie": flowStoreCookie}) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 830 | return |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 831 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 832 | var classifierProto *openoltpb2.Classifier |
| 833 | var actionProto *openoltpb2.Action |
| 834 | 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] | 835 | |
| 836 | if classifierProto = makeOpenOltClassifierField(uplinkClassifier); classifierProto == nil { |
| 837 | log.Error("Error in making classifier protobuf for ul flow") |
| 838 | return |
| 839 | } |
| 840 | log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto}) |
| 841 | if actionProto = makeOpenOltActionField(uplinkAction); actionProto == nil { |
| 842 | log.Error("Error in making action protobuf for ul flow") |
| 843 | return |
| 844 | } |
| 845 | log.Debugw("Created action proto", log.Fields{"action": *actionProto}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 846 | networkIntfID, err = getNniIntfID(classifier, action) |
| 847 | if err != nil { |
| 848 | log.Error("Failed to get nniIntf ID") |
| 849 | return |
| 850 | } |
| 851 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 852 | upstreamFlow = openoltpb2.Flow{AccessIntfId: int32(intfID), |
| 853 | OnuId: int32(onuID), |
| 854 | UniId: int32(uniID), |
| 855 | FlowId: uplinkFlowID, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 856 | FlowType: Upstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 857 | AllocId: int32(allocID), |
| 858 | NetworkIntfId: int32(networkIntfID), |
| 859 | GemportId: int32(gemPortID), |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 860 | Classifier: classifierProto, |
| 861 | Action: actionProto, |
| 862 | Priority: int32(logicalFlow.Priority), |
| 863 | Cookie: logicalFlow.Cookie, |
| 864 | PortNo: portNo} |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 865 | if ok := f.addFlowToDevice(logicalFlow, &upstreamFlow); ok { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 866 | log.Debug("EAPOL UL flow added to device successfully") |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 867 | flowCategory := "EAPOL" |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 868 | flowsToKVStore := f.getUpdatedFlowInfo(&upstreamFlow, flowStoreCookie, flowCategory, uplinkFlowID, logicalFlow.Id) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 869 | if err := f.updateFlowInfoToKVStore(upstreamFlow.AccessIntfId, |
| 870 | upstreamFlow.OnuId, |
| 871 | upstreamFlow.UniId, |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 872 | upstreamFlow.FlowId, |
| 873 | /* lowCategory, */ |
| 874 | flowsToKVStore); err != nil { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 875 | log.Errorw("Error uploading EAPOL UL flow into KV store", log.Fields{"flow": upstreamFlow, "error": err}) |
| 876 | return |
| 877 | } |
| 878 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 879 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 880 | log.Debugw("Added EAPOL flows to device successfully", log.Fields{"flow": logicalFlow}) |
| 881 | } |
| 882 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 883 | func makeOpenOltClassifierField(classifierInfo map[string]interface{}) *openoltpb2.Classifier { |
| 884 | var classifier openoltpb2.Classifier |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 885 | |
| 886 | classifier.EthType, _ = classifierInfo[EthType].(uint32) |
| 887 | classifier.IpProto, _ = classifierInfo[IPProto].(uint32) |
| 888 | if vlanID, ok := classifierInfo[VlanVid].(uint32); ok { |
| 889 | vid := vlanID & VlanvIDMask |
| 890 | if vid != ReservedVlan { |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 891 | classifier.OVid = vid |
| 892 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 893 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 894 | if metadata, ok := classifierInfo[Metadata].(uint64); ok { |
| 895 | vid := uint32(metadata) |
| 896 | if vid != ReservedVlan { |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 897 | classifier.IVid = vid |
| 898 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 899 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 900 | if vlanPcp, ok := classifierInfo[VlanPcp].(uint32); ok { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 901 | if vlanPcp == 0 { |
| 902 | classifier.OPbits = VlanPCPMask |
| 903 | } else { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 904 | classifier.OPbits = vlanPcp & VlanPCPMask |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 905 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 906 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 907 | classifier.SrcPort, _ = classifierInfo[UDPSrc].(uint32) |
| 908 | classifier.DstPort, _ = classifierInfo[UDPDst].(uint32) |
| 909 | classifier.DstIp, _ = classifierInfo[Ipv4Dst].(uint32) |
| 910 | classifier.SrcIp, _ = classifierInfo[Ipv4Src].(uint32) |
| 911 | if pktTagType, ok := classifierInfo[PacketTagType].(string); ok { |
| 912 | classifier.PktTagType = pktTagType |
| 913 | |
| 914 | switch pktTagType { |
| 915 | case SingleTag: |
| 916 | case DoubleTag: |
| 917 | case Untagged: |
| 918 | default: |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 919 | log.Error("Invalid tag type in classifier") // should not hit |
| 920 | return nil |
| 921 | } |
| 922 | } |
| 923 | return &classifier |
| 924 | } |
| 925 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 926 | func makeOpenOltActionField(actionInfo map[string]interface{}) *openoltpb2.Action { |
| 927 | var actionCmd openoltpb2.ActionCmd |
| 928 | var action openoltpb2.Action |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 929 | action.Cmd = &actionCmd |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 930 | if _, ok := actionInfo[PopVlan]; ok { |
| 931 | action.OVid = actionInfo[VlanVid].(uint32) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 932 | action.Cmd.RemoveOuterTag = true |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 933 | } else if _, ok := actionInfo[PushVlan]; ok { |
| 934 | action.OVid = actionInfo[VlanVid].(uint32) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 935 | action.Cmd.AddOuterTag = true |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 936 | } else if _, ok := actionInfo[TrapToHost]; ok { |
| 937 | action.Cmd.TrapToHost = actionInfo[TrapToHost].(bool) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 938 | } else { |
| 939 | log.Errorw("Invalid-action-field", log.Fields{"action": actionInfo}) |
| 940 | return nil |
| 941 | } |
| 942 | return &action |
| 943 | } |
| 944 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 945 | func (f *OpenOltFlowMgr) getTPpath(intfID uint32, uni string, TpID uint32) string { |
| 946 | return f.techprofile[intfID].GetTechProfileInstanceKVPath(TpID, uni) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 947 | } |
| 948 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 949 | // DeleteTechProfileInstances removes the tech profile instances from persistent storage |
| 950 | func (f *OpenOltFlowMgr) DeleteTechProfileInstances(intfID uint32, onuID uint32, uniID uint32, sn string) error { |
| 951 | tpIDList := f.resourceMgr.GetTechProfileIDForOnu(intfID, onuID, uniID) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 952 | uniPortName := fmt.Sprintf("pon-{%d}/onu-{%d}/uni-{%d}", intfID, onuID, uniID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 953 | for _, tpID := range tpIDList { |
| 954 | if err := f.DeleteTechProfileInstance(intfID, onuID, uniID, uniPortName, tpID); err != nil { |
| 955 | 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] | 956 | // return err |
| 957 | // We should continue to delete tech-profile instances for other TP IDs |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | return nil |
| 961 | } |
| 962 | |
| 963 | // DeleteTechProfileInstance removes the tech profile instance from persistent storage |
| 964 | func (f *OpenOltFlowMgr) DeleteTechProfileInstance(intfID uint32, onuID uint32, uniID uint32, uniPortName string, tpID uint32) error { |
| 965 | if uniPortName == "" { |
| 966 | uniPortName = fmt.Sprintf("pon-{%d}/onu-{%d}/uni-{%d}", intfID, onuID, uniID) |
| 967 | } |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 968 | if err := f.techprofile[intfID].DeleteTechProfileInstance(tpID, uniPortName); err != nil { |
| 969 | log.Debugw("Failed-to-delete-tp-instance-from-kv-store", log.Fields{"tp-id": tpID, "uni-port-name": uniPortName}) |
| 970 | return err |
| 971 | } |
| 972 | return nil |
| 973 | } |
| 974 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 975 | func getFlowStoreCookie(classifier map[string]interface{}, gemPortID uint32) uint64 { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 976 | if len(classifier) == 0 { // should never happen |
| 977 | log.Error("Invalid classfier object") |
| 978 | return 0 |
| 979 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 980 | log.Debugw("generating flow store cookie", log.Fields{"classifier": classifier, "gemPortID": gemPortID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 981 | var jsonData []byte |
| 982 | var flowString string |
| 983 | var err error |
| 984 | // TODO: Do we need to marshall ?? |
| 985 | if jsonData, err = json.Marshal(classifier); err != nil { |
| 986 | log.Error("Failed to encode classifier") |
| 987 | return 0 |
| 988 | } |
| 989 | flowString = string(jsonData) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 990 | if gemPortID != 0 { |
| 991 | flowString = fmt.Sprintf("%s%s", string(jsonData), string(gemPortID)) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 992 | } |
| 993 | h := md5.New() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 994 | _, _ = h.Write([]byte(flowString)) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 995 | hash := big.NewInt(0) |
| 996 | hash.SetBytes(h.Sum(nil)) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 997 | generatedHash := hash.Uint64() |
| 998 | log.Debugw("hash generated", log.Fields{"hash": generatedHash}) |
| 999 | return generatedHash |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1000 | } |
| 1001 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1002 | func (f *OpenOltFlowMgr) getUpdatedFlowInfo(flow *openoltpb2.Flow, flowStoreCookie uint64, flowCategory string, deviceFlowID uint32, logicalFlowID uint64) *[]rsrcMgr.FlowInfo { |
| 1003 | var flows = []rsrcMgr.FlowInfo{{Flow: flow, FlowCategory: flowCategory, FlowStoreCookie: flowStoreCookie, LogicalFlowID: logicalFlowID}} |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1004 | var intfID uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1005 | /* For flows which trap out of the NNI, the AccessIntfId is invalid |
| 1006 | (set to -1). In such cases, we need to refer to the NetworkIntfId . |
| 1007 | */ |
| 1008 | if flow.AccessIntfId != -1 { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1009 | intfID = uint32(flow.AccessIntfId) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1010 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1011 | intfID = uint32(flow.NetworkIntfId) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1012 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1013 | // Get existing flows matching flowid for given subscriber from KV store |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1014 | existingFlows := f.resourceMgr.GetFlowIDInfo(intfID, flow.OnuId, flow.UniId, flow.FlowId) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1015 | if existingFlows != nil { |
| 1016 | 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] | 1017 | //for _, f := range *existingFlows { |
| 1018 | // flows = append(flows, f) |
| 1019 | //} |
| 1020 | flows = append(flows, *existingFlows...) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1021 | } |
| 1022 | 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] | 1023 | return &flows |
| 1024 | } |
| 1025 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1026 | //func (f *OpenOltFlowMgr) getUpdatedFlowInfo(flow *openolt_pb2.Flow, flowStoreCookie uint64, flowCategory string) *[]rsrcMgr.FlowInfo { |
| 1027 | // var flows []rsrcMgr.FlowInfo = []rsrcMgr.FlowInfo{rsrcMgr.FlowInfo{Flow: flow, FlowCategory: flowCategory, FlowStoreCookie: flowStoreCookie}} |
| 1028 | // var intfId uint32 |
| 1029 | // /* For flows which trap out of the NNI, the AccessIntfId is invalid |
| 1030 | // (set to -1). In such cases, we need to refer to the NetworkIntfId . |
| 1031 | // */ |
| 1032 | // if flow.AccessIntfId != -1 { |
| 1033 | // intfId = uint32(flow.AccessIntfId) |
| 1034 | // } else { |
| 1035 | // intfId = uint32(flow.NetworkIntfId) |
| 1036 | // } |
| 1037 | // // Get existing flows matching flowid for given subscriber from KV store |
| 1038 | // existingFlows := f.resourceMgr.GetFlowIDInfo(intfId, uint32(flow.OnuId), uint32(flow.UniId), flow.FlowId) |
| 1039 | // if existingFlows != nil { |
| 1040 | // log.Debugw("Flow exists for given flowID, appending it to current flow", log.Fields{"flowID": flow.FlowId}) |
| 1041 | // for _, f := range *existingFlows { |
| 1042 | // flows = append(flows, f) |
| 1043 | // } |
| 1044 | // } |
| 1045 | // log.Debugw("Updated flows for given flowID and onuid", log.Fields{"updatedflow": flows, "flowid": flow.FlowId, "onu": flow.OnuId}) |
| 1046 | // return &flows |
| 1047 | //} |
| 1048 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1049 | func (f *OpenOltFlowMgr) updateFlowInfoToKVStore(intfID int32, onuID int32, uniID int32, flowID uint32, flows *[]rsrcMgr.FlowInfo) error { |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1050 | log.Debugw("Storing flow(s) into KV store", log.Fields{"flows": *flows}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1051 | if err := f.resourceMgr.UpdateFlowIDInfo(intfID, onuID, uniID, flowID, flows); err != nil { |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1052 | log.Debug("Error while Storing flow into KV store") |
| 1053 | return err |
| 1054 | } |
| 1055 | log.Info("Stored flow(s) into KV store successfully!") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1056 | return nil |
| 1057 | } |
| 1058 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1059 | func (f *OpenOltFlowMgr) addFlowToDevice(logicalFlow *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) bool { |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1060 | |
| 1061 | var intfID uint32 |
| 1062 | /* For flows which trap out of the NNI, the AccessIntfId is invalid |
| 1063 | (set to -1). In such cases, we need to refer to the NetworkIntfId . |
| 1064 | */ |
| 1065 | if deviceFlow.AccessIntfId != -1 { |
| 1066 | intfID = uint32(deviceFlow.AccessIntfId) |
| 1067 | } else { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1068 | // REVIST : Why ponport is given as network port? |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1069 | intfID = uint32(deviceFlow.NetworkIntfId) |
| 1070 | } |
| 1071 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1072 | log.Debugw("Sending flow to device via grpc", log.Fields{"flow": *deviceFlow}) |
| 1073 | _, err := f.deviceHandler.Client.FlowAdd(context.Background(), deviceFlow) |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1074 | |
| 1075 | st, _ := status.FromError(err) |
| 1076 | if st.Code() == codes.AlreadyExists { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1077 | log.Debug("Flow already exists", log.Fields{"err": err, "deviceFlow": deviceFlow}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1078 | return true |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1079 | } |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1080 | |
| 1081 | if err != nil { |
| 1082 | log.Errorw("Failed to Add flow to device", log.Fields{"err": err, "deviceFlow": deviceFlow}) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1083 | f.resourceMgr.FreeFlowID(intfID, deviceFlow.OnuId, deviceFlow.UniId, deviceFlow.FlowId) |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1084 | return false |
| 1085 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1086 | f.registerFlow(logicalFlow, deviceFlow) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1087 | log.Debugw("Flow added to device successfully ", log.Fields{"flow": *deviceFlow}) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1088 | return true |
| 1089 | } |
| 1090 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1091 | func (f *OpenOltFlowMgr) removeFlowFromDevice(deviceFlow *openoltpb2.Flow) bool { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1092 | log.Debugw("Sending flow to device via grpc", log.Fields{"flow": *deviceFlow}) |
| 1093 | _, err := f.deviceHandler.Client.FlowRemove(context.Background(), deviceFlow) |
| 1094 | if err != nil { |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1095 | if f.deviceHandler.device.ConnectStatus == common.ConnectStatus_UNREACHABLE { |
| 1096 | log.Warnw("Can not remove flow from device since it's unreachable", log.Fields{"err": err, "deviceFlow": deviceFlow}) |
| 1097 | //Assume the flow is removed |
| 1098 | return true |
| 1099 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1100 | log.Errorw("Failed to Remove flow from device", log.Fields{"err": err, "deviceFlow": deviceFlow}) |
| 1101 | return false |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1102 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1103 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1104 | log.Debugw("Flow removed from device successfully ", log.Fields{"flow": *deviceFlow}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1105 | return true |
| 1106 | } |
| 1107 | |
| 1108 | /*func register_flow(deviceFlow *openolt_pb2.Flow, logicalFlow *ofp.OfpFlowStats){ |
| 1109 | //update core flows_proxy : flows_proxy.update('/', flows) |
| 1110 | } |
| 1111 | |
| 1112 | func generateStoredId(flowId uint32, direction string)uint32{ |
| 1113 | |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1114 | if direction == Upstream{ |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1115 | log.Debug("Upstream flow shifting flowid") |
| 1116 | return ((0x1 << 15) | flowId) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1117 | }else if direction == Downstream{ |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1118 | log.Debug("Downstream flow not shifting flowid") |
| 1119 | return flowId |
| 1120 | }else{ |
| 1121 | log.Errorw("Unrecognized direction",log.Fields{"direction": direction}) |
| 1122 | return flowId |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | */ |
| 1127 | |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1128 | func (f *OpenOltFlowMgr) addLLDPFlow(flow *ofp.OfpFlowStats, portNo uint32) { |
| 1129 | |
| 1130 | classifierInfo := make(map[string]interface{}) |
| 1131 | actionInfo := make(map[string]interface{}) |
| 1132 | |
| 1133 | classifierInfo[EthType] = uint32(LldpEthType) |
| 1134 | classifierInfo[PacketTagType] = Untagged |
| 1135 | actionInfo[TrapToHost] = true |
| 1136 | |
| 1137 | // LLDP flow is installed to trap LLDP packets on the NNI port. |
| 1138 | // We manage flow_id resource pool on per PON port basis. |
| 1139 | // Since this situation is tricky, as a hack, we pass the NNI port |
| 1140 | // index (network_intf_id) as PON port Index for the flow_id resource |
| 1141 | // pool. Also, there is no ONU Id available for trapping LLDP packets |
| 1142 | // on NNI port, use onu_id as -1 (invalid) |
| 1143 | // ****************** CAVEAT ******************* |
| 1144 | // This logic works if the NNI Port Id falls within the same valid |
| 1145 | // range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 1146 | // we need to have a re-look at this. |
| 1147 | // ********************************************* |
| 1148 | |
| 1149 | var onuID = -1 |
| 1150 | var uniID = -1 |
| 1151 | var gemPortID = -1 |
| 1152 | |
| 1153 | var networkInterfaceID = IntfIDFromNniPortNum(portNo) |
| 1154 | var flowStoreCookie = getFlowStoreCookie(classifierInfo, uint32(0)) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1155 | if present := f.resourceMgr.IsFlowCookieOnKVStore(uint32(networkInterfaceID), int32(onuID), int32(uniID), flowStoreCookie); present { |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1156 | log.Debug("Flow-exists--not-re-adding") |
| 1157 | return |
| 1158 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1159 | flowID, err := f.resourceMgr.GetFlowID(uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1160 | |
| 1161 | if err != nil { |
| 1162 | log.Errorw("Flow id unavailable for LLDP traponNNI flow", log.Fields{"error": err}) |
| 1163 | return |
| 1164 | } |
| 1165 | var classifierProto *openoltpb2.Classifier |
| 1166 | var actionProto *openoltpb2.Action |
| 1167 | if classifierProto = makeOpenOltClassifierField(classifierInfo); classifierProto == nil { |
| 1168 | log.Error("Error in making classifier protobuf for LLDP trap on nni flow") |
| 1169 | return |
| 1170 | } |
| 1171 | log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto}) |
| 1172 | if actionProto = makeOpenOltActionField(actionInfo); actionProto == nil { |
| 1173 | log.Error("Error in making action protobuf for LLDP trap on nni flow") |
| 1174 | return |
| 1175 | } |
| 1176 | log.Debugw("Created action proto", log.Fields{"action": *actionProto}) |
| 1177 | |
| 1178 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 1179 | OnuId: int32(onuID), // OnuId not required |
| 1180 | UniId: int32(uniID), // UniId not used |
| 1181 | FlowId: flowID, |
| 1182 | FlowType: Downstream, |
| 1183 | NetworkIntfId: int32(networkInterfaceID), |
| 1184 | GemportId: int32(gemPortID), |
| 1185 | Classifier: classifierProto, |
| 1186 | Action: actionProto, |
| 1187 | Priority: int32(flow.Priority), |
| 1188 | Cookie: flow.Cookie, |
| 1189 | PortNo: portNo} |
| 1190 | if ok := f.addFlowToDevice(flow, &downstreamflow); ok { |
| 1191 | log.Debug("LLDP trap on NNI flow added to device successfully") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1192 | flowsToKVStore := f.getUpdatedFlowInfo(&downstreamflow, flowStoreCookie, "", flowID, flow.Id) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1193 | if err := f.updateFlowInfoToKVStore(int32(networkInterfaceID), |
| 1194 | int32(onuID), |
| 1195 | int32(uniID), |
| 1196 | flowID, flowsToKVStore); err != nil { |
| 1197 | log.Errorw("Error uploading LLDP flow into KV store", log.Fields{"flow": downstreamflow, "error": err}) |
| 1198 | } |
| 1199 | } |
| 1200 | return |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1201 | } |
| 1202 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1203 | func getUniPortPath(intfID uint32, onuID int32, uniID int32) string { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1204 | return fmt.Sprintf("pon-{%d}/onu-{%d}/uni-{%d}", intfID, onuID, uniID) |
| 1205 | } |
| 1206 | |
| 1207 | //getOnuChildDevice to fetch onu |
| 1208 | func (f *OpenOltFlowMgr) getOnuChildDevice(intfID uint32, onuID uint32) (*voltha.Device, error) { |
| 1209 | log.Debugw("GetChildDevice", log.Fields{"pon port": intfID, "onuId": onuID}) |
| 1210 | parentPortNo := IntfIDToPortNo(intfID, voltha.Port_PON_OLT) |
| 1211 | onuDevice := f.deviceHandler.GetChildDevice(parentPortNo, onuID) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1212 | if onuDevice == nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1213 | log.Errorw("onu not found", log.Fields{"intfId": parentPortNo, "onuId": onuID}) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1214 | return nil, errors.New("onu not found") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1215 | } |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1216 | log.Debugw("Successfully received child device from core", log.Fields{"child_device": *onuDevice}) |
| 1217 | return onuDevice, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | func findNextFlow(flow *ofp.OfpFlowStats) *ofp.OfpFlowStats { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1221 | log.Info("unimplemented flow : %v", flow) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1222 | return nil |
| 1223 | } |
| 1224 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1225 | func (f *OpenOltFlowMgr) clearFlowsAndSchedulerForLogicalPort(childDevice *voltha.Device, logicalPort *voltha.LogicalPort) { |
| 1226 | log.Info("unimplemented device %v, logicalport %v", childDevice, logicalPort) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1227 | } |
| 1228 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1229 | func (f *OpenOltFlowMgr) decodeStoredID(id uint64) (uint64, string) { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1230 | if id>>15 == 0x1 { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1231 | return id & 0x7fff, Upstream |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1232 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1233 | return id, Downstream |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1234 | } |
| 1235 | |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1236 | func (f *OpenOltFlowMgr) sendDeleteGemPortToChild(intfID uint32, onuID uint32, uniID uint32, gemPortID uint32, tpPath string) error { |
| 1237 | onuDevice, err := f.getOnuChildDevice(intfID, onuID) |
| 1238 | if err != nil { |
| 1239 | log.Errorw("error fetching child device from core", log.Fields{"onuId": onuID}) |
| 1240 | return err |
| 1241 | } |
| 1242 | |
| 1243 | delGemPortMsg := &ic.InterAdapterDeleteGemPortMessage{UniId: uniID, TpPath: tpPath, GemPortId: gemPortID} |
| 1244 | log.Debugw("sending gem port delete to openonu adapter", log.Fields{"msg": *delGemPortMsg}) |
| 1245 | if sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(context.Background(), |
| 1246 | delGemPortMsg, |
| 1247 | ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST, |
| 1248 | f.deviceHandler.deviceType, |
| 1249 | onuDevice.Type, |
| 1250 | onuDevice.Id, |
| 1251 | onuDevice.ProxyAddress.DeviceId, ""); sendErr != nil { |
| 1252 | log.Errorw("failure sending del gem port to onu adapter", log.Fields{"fromAdapter": f.deviceHandler.deviceType, |
| 1253 | "toAdapter": onuDevice.Type, "onuId": onuDevice.Id, |
| 1254 | "proxyDeviceId": onuDevice.ProxyAddress.DeviceId}) |
| 1255 | return sendErr |
| 1256 | } |
| 1257 | log.Debugw("success sending del gem port to onu adapter", log.Fields{"msg": delGemPortMsg}) |
| 1258 | return nil |
| 1259 | } |
| 1260 | |
| 1261 | func (f *OpenOltFlowMgr) sendDeleteTcontToChild(intfID uint32, onuID uint32, uniID uint32, allocID uint32, tpPath string) error { |
| 1262 | onuDevice, err := f.getOnuChildDevice(intfID, onuID) |
| 1263 | if err != nil { |
| 1264 | log.Errorw("error fetching child device from core", log.Fields{"onuId": onuID}) |
| 1265 | return err |
| 1266 | } |
| 1267 | |
| 1268 | delTcontMsg := &ic.InterAdapterDeleteTcontMessage{UniId: uniID, TpPath: tpPath, AllocId: allocID} |
| 1269 | log.Debugw("sending tcont delete to openonu adapter", log.Fields{"msg": *delTcontMsg}) |
| 1270 | if sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(context.Background(), |
| 1271 | delTcontMsg, |
| 1272 | ic.InterAdapterMessageType_DELETE_TCONT_REQUEST, |
| 1273 | f.deviceHandler.deviceType, |
| 1274 | onuDevice.Type, |
| 1275 | onuDevice.Id, |
| 1276 | onuDevice.ProxyAddress.DeviceId, ""); sendErr != nil { |
| 1277 | log.Errorw("failure sending del tcont to onu adapter", log.Fields{"fromAdapter": f.deviceHandler.deviceType, |
| 1278 | "toAdapter": onuDevice.Type, "onuId": onuDevice.Id, |
| 1279 | "proxyDeviceId": onuDevice.ProxyAddress.DeviceId}) |
| 1280 | return sendErr |
| 1281 | } |
| 1282 | log.Debugw("success sending del tcont to onu adapter", log.Fields{"msg": delTcontMsg}) |
| 1283 | return nil |
| 1284 | } |
| 1285 | |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1286 | func (f *OpenOltFlowMgr) deletePendingFlows(Intf uint32, onuID int32, uniID int32) { |
| 1287 | pnFlDelKey := pendingFlowDeleteKey{Intf, uint32(onuID), uint32(uniID)} |
| 1288 | if val, ok := f.pendingFlowDelete.Load(pnFlDelKey); ok { |
| 1289 | if val.(int) > 0 { |
| 1290 | pnFlDels := val.(int) - 1 |
| 1291 | if pnFlDels > 0 { |
| 1292 | log.Debugw("flow delete succeeded, more pending", |
| 1293 | log.Fields{"intf": Intf, "onuID": onuID, "uniID": uniID, "currPendingFlowCnt": pnFlDels}) |
| 1294 | f.pendingFlowDelete.Store(pnFlDelKey, pnFlDels) |
| 1295 | } else { |
| 1296 | log.Debugw("all pending flow deletes handled, removing entry from map", |
| 1297 | log.Fields{"intf": Intf, "onuID": onuID, "uniID": uniID}) |
| 1298 | f.pendingFlowDelete.Delete(pnFlDelKey) |
| 1299 | } |
| 1300 | } |
| 1301 | } else { |
| 1302 | log.Debugw("no pending delete flows found", |
| 1303 | log.Fields{"intf": Intf, "onuID": onuID, "uniID": uniID}) |
| 1304 | |
| 1305 | } |
| 1306 | |
| 1307 | } |
| 1308 | |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 1309 | //clearResources clears pon resources in kv store and the device |
| 1310 | func (f *OpenOltFlowMgr) clearResources(flow *ofp.OfpFlowStats, Intf uint32, onuID int32, uniID int32, |
| 1311 | gemPortID int32, flowID uint32, flowDirection string, |
| 1312 | portNum uint32, updatedFlows []rsrcMgr.FlowInfo) error { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1313 | |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 1314 | tpID, err := getTpIDFromFlow(flow) |
| 1315 | if err != nil { |
| 1316 | log.Error("metadata-is-not-present-invalid-flow-to-process", log.Fields{"pon": Intf, "onuID": onuID, "uniID": uniID}) |
| 1317 | return err |
| 1318 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1319 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1320 | if len(updatedFlows) >= 0 { |
| 1321 | // There are still flows referencing the same flow_id. |
| 1322 | // So the flow should not be freed yet. |
| 1323 | // For ex: Case of HSIA where same flow is shared |
| 1324 | // between DS and US. |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1325 | f.updateFlowInfoToKVStore(int32(Intf), int32(onuID), int32(uniID), flowID, &updatedFlows) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1326 | if len(updatedFlows) == 0 { |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1327 | // Do this for subscriber flows only (not trap from NNI flows) |
| 1328 | if onuID != -1 && uniID != -1 { |
| 1329 | pnFlDelKey := pendingFlowDeleteKey{Intf, uint32(onuID), uint32(uniID)} |
| 1330 | if val, ok := f.pendingFlowDelete.Load(pnFlDelKey); !ok { |
| 1331 | log.Debugw("creating entry for pending flow delete", |
| 1332 | log.Fields{"intf": Intf, "onuID": onuID, "uniID": uniID}) |
| 1333 | f.pendingFlowDelete.Store(pnFlDelKey, 1) |
| 1334 | } else { |
| 1335 | pnFlDels := val.(int) + 1 |
| 1336 | log.Debugw("updating flow delete entry", |
| 1337 | log.Fields{"intf": Intf, "onuID": onuID, "uniID": uniID, "currPendingFlowCnt": pnFlDels}) |
| 1338 | f.pendingFlowDelete.Store(pnFlDelKey, pnFlDels) |
| 1339 | } |
| 1340 | |
| 1341 | defer f.deletePendingFlows(Intf, onuID, uniID) |
| 1342 | } |
| 1343 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1344 | log.Debugw("Releasing flow Id to resource manager", log.Fields{"Intf": Intf, "onuId": onuID, "uniId": uniID, "flowId": flowID}) |
| 1345 | f.resourceMgr.FreeFlowID(Intf, int32(onuID), int32(uniID), flowID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1346 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1347 | uni := getUniPortPath(Intf, onuID, uniID) |
| 1348 | tpPath := f.getTPpath(Intf, uni, tpID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1349 | log.Debugw("Getting-techprofile-instance-for-subscriber", log.Fields{"TP-PATH": tpPath}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1350 | techprofileInst, err := f.techprofile[Intf].GetTPInstanceFromKVStore(tpID, tpPath) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1351 | if err != nil { // This should not happen, something wrong in KV backend transaction |
| 1352 | 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] | 1353 | return err |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1354 | } |
| 1355 | if techprofileInst == nil { |
| 1356 | 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] | 1357 | return err |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1360 | gemPK := gemPortKey{Intf, uint32(gemPortID)} |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1361 | if f.isGemPortUsedByAnotherFlow(gemPK) { |
| 1362 | flowIDs := f.flowsUsedByGemPort[gemPK] |
| 1363 | for i, flowIDinMap := range flowIDs { |
| 1364 | if flowIDinMap == flowID { |
| 1365 | flowIDs = append(flowIDs[:i], flowIDs[i+1:]...) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1366 | // everytime flowsUsedByGemPort cache is updated the same should be updated |
| 1367 | // in kv store by calling UpdateFlowIDsForGem |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1368 | f.flowsUsedByGemPort[gemPK] = flowIDs |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1369 | f.resourceMgr.UpdateFlowIDsForGem(Intf, uint32(gemPortID), flowIDs) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1370 | break |
| 1371 | } |
| 1372 | } |
| 1373 | 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] | 1374 | return nil |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1375 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1376 | log.Debugf("Gem port id %d is not used by another flow - releasing the gem port", gemPortID) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1377 | f.resourceMgr.RemoveGemPortIDForOnu(Intf, uint32(onuID), uint32(uniID), uint32(gemPortID)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1378 | // TODO: The TrafficQueue corresponding to this gem-port also should be removed immediately. |
| 1379 | // But it is anyway eventually removed later when the TechProfile is freed, so not a big issue for now. |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1380 | f.resourceMgr.RemoveGEMportPonportToOnuMapOnKVStore(uint32(gemPortID), Intf) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1381 | f.onuIdsLock.Lock() |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1382 | //everytime an entry is deleted from flowsUsedByGemPort cache, the same should be updated in kv as well |
| 1383 | // by calling DeleteFlowIDsForGem |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1384 | delete(f.flowsUsedByGemPort, gemPK) |
Abhilash Laxmeshwar | 275c074 | 2019-11-25 16:47:02 +0530 | [diff] [blame] | 1385 | f.resourceMgr.DeleteFlowIDsForGem(Intf, uint32(gemPortID)) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1386 | f.resourceMgr.FreeGemPortID(Intf, uint32(onuID), uint32(uniID), uint32(gemPortID)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1387 | f.onuIdsLock.Unlock() |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1388 | // Delete the gem port on the ONU. |
| 1389 | if err := f.sendDeleteGemPortToChild(Intf, uint32(onuID), uint32(uniID), uint32(gemPortID), tpPath); err != nil { |
| 1390 | log.Errorw("error processing delete gem-port towards onu", |
| 1391 | log.Fields{"err": err, "pon": Intf, "onuID": onuID, "uniID": uniID, "gemPortId": gemPortID}) |
| 1392 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1393 | |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 1394 | ok, _ := f.isTechProfileUsedByAnotherGem(Intf, uint32(onuID), uint32(uniID), tpID, techprofileInst, uint32(gemPortID)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1395 | if !ok { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1396 | f.resourceMgr.RemoveTechProfileIDForOnu(Intf, uint32(onuID), uint32(uniID), tpID) |
| 1397 | f.RemoveSchedulerQueues(schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: Intf, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst}) |
| 1398 | f.RemoveSchedulerQueues(schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: Intf, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst}) |
| 1399 | f.DeleteTechProfileInstance(Intf, uint32(onuID), uint32(uniID), "", tpID) |
| 1400 | f.resourceMgr.FreeAllocID(Intf, uint32(onuID), uint32(uniID), techprofileInst.UsScheduler.AllocID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1401 | // Delete the TCONT on the ONU. |
| 1402 | if err := f.sendDeleteTcontToChild(Intf, uint32(onuID), uint32(uniID), uint32(techprofileInst.UsScheduler.AllocID), tpPath); err != nil { |
| 1403 | log.Errorw("error processing delete tcont towards onu", |
| 1404 | log.Fields{"pon": Intf, "onuID": onuID, "uniID": uniID, "allocId": techprofileInst.UsScheduler.AllocID}) |
| 1405 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1406 | } |
| 1407 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1408 | } |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 1409 | return nil |
| 1410 | } |
| 1411 | |
| 1412 | func (f *OpenOltFlowMgr) clearFlowFromResourceManager(flow *ofp.OfpFlowStats, flowDirection string) { |
| 1413 | |
| 1414 | log.Debugw("clearFlowFromResourceManager", log.Fields{"flowDirection": flowDirection, "flow": *flow}) |
| 1415 | var updatedFlows []rsrcMgr.FlowInfo |
| 1416 | var flowID uint32 |
| 1417 | var onuID, uniID int32 |
| 1418 | classifierInfo := make(map[string]interface{}) |
| 1419 | |
| 1420 | portNum, Intf, onu, uni, inPort, ethType, err := FlowExtractInfo(flow, flowDirection) |
| 1421 | if err != nil { |
| 1422 | log.Error(err) |
| 1423 | return |
| 1424 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1425 | |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 1426 | onuID = int32(onu) |
| 1427 | uniID = int32(uni) |
| 1428 | |
| 1429 | for _, field := range flows.GetOfbFields(flow) { |
| 1430 | if field.Type == flows.IP_PROTO { |
| 1431 | classifierInfo[IPProto] = field.GetIpProto() |
| 1432 | log.Debug("field-type-ip-proto", log.Fields{"classifierInfo[IP_PROTO]": classifierInfo[IPProto].(uint32)}) |
| 1433 | } |
| 1434 | } |
| 1435 | log.Debugw("Extracted access info from flow to be deleted", |
| 1436 | log.Fields{"ponIntf": Intf, "onuID": onuID, "uniID": uniID}) |
| 1437 | |
| 1438 | if ethType == LldpEthType || ((classifierInfo[IPProto] == IPProtoDhcp) && (flowDirection == "downstream")) { |
| 1439 | onuID = -1 |
| 1440 | uniID = -1 |
| 1441 | log.Debug("Trap on nni flow set oni, uni to -1") |
| 1442 | Intf = IntfIDFromNniPortNum(inPort) |
| 1443 | } |
| 1444 | flowIds := f.resourceMgr.GetCurrentFlowIDsForOnu(Intf, onuID, uniID) |
| 1445 | for _, flowID = range flowIds { |
| 1446 | flowInfo := f.resourceMgr.GetFlowIDInfo(Intf, onuID, uniID, flowID) |
| 1447 | if flowInfo == nil { |
| 1448 | log.Debugw("No FlowInfo found found in KV store", |
| 1449 | log.Fields{"Intf": Intf, "onuID": onuID, "uniID": uniID, "flowID": flowID}) |
| 1450 | return |
| 1451 | } |
| 1452 | updatedFlows = nil |
| 1453 | for _, flow := range *flowInfo { |
| 1454 | updatedFlows = append(updatedFlows, flow) |
| 1455 | } |
| 1456 | |
| 1457 | for i, storedFlow := range updatedFlows { |
| 1458 | if flow.Id == storedFlow.LogicalFlowID { |
| 1459 | removeFlowMessage := openoltpb2.Flow{FlowId: storedFlow.Flow.FlowId, FlowType: storedFlow.Flow.FlowType} |
| 1460 | log.Debugw("Flow to be deleted", log.Fields{"flow": storedFlow}) |
| 1461 | if ok := f.removeFlowFromDevice(&removeFlowMessage); ok { |
| 1462 | log.Debug("Flow removed from device successfully") |
| 1463 | //Remove the Flow from FlowInfo |
| 1464 | updatedFlows = append(updatedFlows[:i], updatedFlows[i+1:]...) |
| 1465 | err = f.clearResources(flow, Intf, onuID, uniID, storedFlow.Flow.GemportId, |
| 1466 | flowID, flowDirection, portNum, updatedFlows) |
| 1467 | if err != nil { |
| 1468 | log.Error("Failed to clear resources for flow", log.Fields{"flow": storedFlow}) |
| 1469 | return |
| 1470 | } |
| 1471 | } else { |
| 1472 | log.Error("Failed to remove flow from device") |
| 1473 | return |
| 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1478 | } |
| 1479 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1480 | //RemoveFlow removes the flow from the device |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1481 | func (f *OpenOltFlowMgr) RemoveFlow(flow *ofp.OfpFlowStats) { |
| 1482 | log.Debugw("Removing Flow", log.Fields{"flow": flow}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1483 | var direction string |
| 1484 | actionInfo := make(map[string]interface{}) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1485 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1486 | for _, action := range flows.GetActions(flow) { |
| 1487 | if action.Type == flows.OUTPUT { |
| 1488 | if out := action.GetOutput(); out != nil { |
| 1489 | actionInfo[Output] = out.GetPort() |
| 1490 | log.Debugw("action-type-output", log.Fields{"out_port": actionInfo[Output].(uint32)}) |
| 1491 | } else { |
| 1492 | log.Error("Invalid output port in action") |
| 1493 | return |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1494 | } |
| 1495 | } |
| 1496 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1497 | if IsUpstream(actionInfo[Output].(uint32)) { |
| 1498 | direction = Upstream |
| 1499 | } else { |
| 1500 | direction = Downstream |
| 1501 | } |
| 1502 | |
| 1503 | f.clearFlowFromResourceManager(flow, direction) //TODO: Take care of the limitations |
| 1504 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1505 | return |
| 1506 | } |
| 1507 | |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1508 | func (f *OpenOltFlowMgr) waitForFlowDeletesToCompleteForOnu(ctx context.Context, intfID uint32, onuID uint32, |
| 1509 | uniID uint32, ch chan bool) { |
| 1510 | pnFlDelKey := pendingFlowDeleteKey{intfID, onuID, uniID} |
| 1511 | for { |
| 1512 | select { |
| 1513 | case <-time.After(20 * time.Millisecond): |
| 1514 | if flowDelRefCnt, ok := f.pendingFlowDelete.Load(pnFlDelKey); !ok || flowDelRefCnt == 0 { |
| 1515 | log.Debug("pending flow deletes completed") |
| 1516 | ch <- true |
| 1517 | return |
| 1518 | } |
| 1519 | case <-ctx.Done(): |
| 1520 | log.Error("flow delete wait handler routine canceled") |
| 1521 | return |
| 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1526 | // AddFlow add flow to device |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1527 | func (f *OpenOltFlowMgr) AddFlow(flow *ofp.OfpFlowStats, flowMetadata *voltha.FlowMetadata) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1528 | classifierInfo := make(map[string]interface{}) |
| 1529 | actionInfo := make(map[string]interface{}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1530 | var UsMeterID uint32 |
| 1531 | var DsMeterID uint32 |
| 1532 | |
| 1533 | log.Debug("Adding Flow", log.Fields{"flow": flow, "flowMetadata": flowMetadata}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1534 | formulateClassifierInfoFromFlow(classifierInfo, flow) |
| 1535 | |
| 1536 | err := formulateActionInfoFromFlow(actionInfo, classifierInfo, flow) |
| 1537 | if err != nil { |
| 1538 | // Error logging is already done in the called function |
| 1539 | // So just return in case of error |
| 1540 | return |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1541 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1542 | |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1543 | /* Controller bound trap flows */ |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1544 | err = formulateControllerBoundTrapFlowInfo(actionInfo, classifierInfo, flow) |
| 1545 | if err != nil { |
| 1546 | // error if any, already logged in the called function |
| 1547 | return |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1548 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1549 | |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1550 | log.Infow("Flow ports", log.Fields{"classifierInfo_inport": classifierInfo[InPort], "action_output": actionInfo[Output]}) |
| 1551 | portNo, intfID, onuID, uniID := ExtractAccessFromFlow(classifierInfo[InPort].(uint32), actionInfo[Output].(uint32)) |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 1552 | |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1553 | if ethType, ok := classifierInfo[EthType]; ok { |
| 1554 | if ethType.(uint32) == LldpEthType { |
| 1555 | log.Info("Adding LLDP flow") |
| 1556 | f.addLLDPFlow(flow, portNo) |
| 1557 | return |
| 1558 | } |
| 1559 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1560 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 1561 | if ipProto.(uint32) == IPProtoDhcp { |
| 1562 | if udpSrc, ok := classifierInfo[UDPSrc]; ok { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1563 | if udpSrc.(uint32) == uint32(67) { |
| 1564 | log.Debug("trap-dhcp-from-nni-flow") |
| 1565 | f.addDHCPTrapFlowOnNNI(flow, classifierInfo, portNo) |
| 1566 | return |
| 1567 | } |
| 1568 | } |
| 1569 | } |
| 1570 | } |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 1571 | |
| 1572 | f.deviceHandler.AddUniPortToOnu(intfID, onuID, portNo) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1573 | f.resourceMgr.AddUniPortToOnuInfo(intfID, onuID, portNo) |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 1574 | |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 1575 | TpID, err := getTpIDFromFlow(flow) |
| 1576 | if err != nil { |
| 1577 | log.Error("metadata-is-not-present-invalid-flow-to-process", log.Fields{"pon": intfID, "onuID": onuID, "uniID": uniID}) |
| 1578 | return |
| 1579 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1580 | 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] | 1581 | if IsUpstream(actionInfo[Output].(uint32)) { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 1582 | UsMeterID = flows.GetMeterIdFromFlow(flow) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1583 | log.Debugw("Upstream-flow-meter-id", log.Fields{"UsMeterID": UsMeterID}) |
| 1584 | } else { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 1585 | DsMeterID = flows.GetMeterIdFromFlow(flow) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1586 | log.Debugw("Downstream-flow-meter-id", log.Fields{"DsMeterID": DsMeterID}) |
| 1587 | |
| 1588 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1589 | |
| 1590 | pnFlDelKey := pendingFlowDeleteKey{intfID, onuID, uniID} |
| 1591 | if _, ok := f.pendingFlowDelete.Load(pnFlDelKey); !ok { |
| 1592 | log.Debugw("no pending flows found, going ahead with flow install", log.Fields{"pon": intfID, "onuID": onuID, "uniID": uniID}) |
| 1593 | f.divideAndAddFlow(intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, uint32(TpID), UsMeterID, DsMeterID, flowMetadata) |
| 1594 | } else { |
| 1595 | ctx := context.Background() |
| 1596 | ctx, cancel := context.WithCancel(ctx) |
| 1597 | defer cancel() |
| 1598 | pendingFlowDelComplete := make(chan bool) |
| 1599 | go f.waitForFlowDeletesToCompleteForOnu(ctx, intfID, onuID, uniID, pendingFlowDelComplete) |
| 1600 | select { |
| 1601 | case <-pendingFlowDelComplete: |
| 1602 | log.Debugw("all pending flow deletes completed", log.Fields{"pon": intfID, "onuID": onuID, "uniID": uniID}) |
| 1603 | f.divideAndAddFlow(intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, uint32(TpID), UsMeterID, DsMeterID, flowMetadata) |
| 1604 | |
| 1605 | case <-time.After(10 * time.Second): |
| 1606 | log.Errorw("pending flow deletes not completed after timeout", log.Fields{"pon": intfID, "onuID": onuID, "uniID": uniID}) |
| 1607 | } |
| 1608 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | //sendTPDownloadMsgToChild send payload |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1612 | 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] | 1613 | |
| 1614 | onuDevice, err := f.getOnuChildDevice(intfID, onuID) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1615 | if err != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1616 | 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] | 1617 | return err |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1618 | } |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1619 | 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] | 1620 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1621 | tpPath := f.getTPpath(intfID, uni, TpID) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1622 | tpDownloadMsg := &ic.InterAdapterTechProfileDownloadMessage{UniId: uniID, Path: tpPath} |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 1623 | log.Infow("Sending Load-tech-profile-request-to-brcm-onu-adapter", log.Fields{"msg": *tpDownloadMsg}) |
| 1624 | sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(context.Background(), |
| 1625 | tpDownloadMsg, |
| 1626 | ic.InterAdapterMessageType_TECH_PROFILE_DOWNLOAD_REQUEST, |
| 1627 | f.deviceHandler.deviceType, |
| 1628 | onuDevice.Type, |
| 1629 | onuDevice.Id, |
| 1630 | onuDevice.ProxyAddress.DeviceId, "") |
| 1631 | if sendErr != nil { |
| 1632 | log.Errorw("send techprofile-download request error", log.Fields{"fromAdapter": f.deviceHandler.deviceType, |
| 1633 | "toAdapter": onuDevice.Type, "onuId": onuDevice.Id, |
| 1634 | "proxyDeviceId": onuDevice.ProxyAddress.DeviceId}) |
| 1635 | return sendErr |
| 1636 | } |
| 1637 | 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] | 1638 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1639 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1640 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1641 | //UpdateOnuInfo function adds onu info to cache and kvstore |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1642 | func (f *OpenOltFlowMgr) UpdateOnuInfo(intfID uint32, onuID uint32, serialNum string) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1643 | |
| 1644 | f.lockCache.Lock() |
| 1645 | defer f.lockCache.Unlock() |
| 1646 | onu := rsrcMgr.OnuGemInfo{OnuID: onuID, SerialNumber: serialNum, IntfID: intfID} |
| 1647 | f.onuGemInfo[intfID] = append(f.onuGemInfo[intfID], onu) |
| 1648 | if err := f.resourceMgr.AddOnuInfo(intfID, onu); err != nil { |
| 1649 | log.Errorw("failed to add onu info", log.Fields{"onu": onu}) |
| 1650 | return |
| 1651 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1652 | log.Debugw("Updated onuinfo", log.Fields{"intfID": intfID, "onuID": onuID, "serialNum": serialNum}) |
| 1653 | } |
| 1654 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1655 | //addGemPortToOnuInfoMap function adds GEMport to ONU map |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1656 | func (f *OpenOltFlowMgr) addGemPortToOnuInfoMap(intfID uint32, onuID uint32, gemPort uint32) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1657 | f.lockCache.Lock() |
| 1658 | defer f.lockCache.Unlock() |
| 1659 | onugem := f.onuGemInfo[intfID] |
| 1660 | // update the gem to the local cache as well as to kv strore |
| 1661 | for idx, onu := range onugem { |
| 1662 | if onu.OnuID == onuID { |
| 1663 | // check if gem already exists , else update the cache and kvstore |
| 1664 | for _, gem := range onu.GemPorts { |
| 1665 | if gem == gemPort { |
| 1666 | log.Debugw("Gem already in cache, no need to update cache and kv store", |
| 1667 | log.Fields{"gem": gemPort}) |
| 1668 | return |
| 1669 | } |
| 1670 | } |
| 1671 | onugem[idx].GemPorts = append(onugem[idx].GemPorts, gemPort) |
| 1672 | f.onuGemInfo[intfID] = onugem |
| 1673 | } |
| 1674 | } |
| 1675 | err := f.resourceMgr.AddGemToOnuGemInfo(intfID, onuID, gemPort) |
| 1676 | if err != nil { |
| 1677 | 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] | 1678 | return |
| 1679 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | // This function Lookup maps by serialNumber or (intfId, gemPort) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1683 | |
| 1684 | //getOnuIDfromGemPortMap Returns OnuID,nil if found or set 0,error if no onuId is found for serialNumber or (intfId, gemPort) |
| 1685 | func (f *OpenOltFlowMgr) getOnuIDfromGemPortMap(serialNumber string, intfID uint32, gemPortID uint32) (uint32, error) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1686 | |
| 1687 | f.lockCache.Lock() |
| 1688 | defer f.lockCache.Unlock() |
| 1689 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1690 | 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] | 1691 | // get onuid from the onugem info cache |
| 1692 | onugem := f.onuGemInfo[intfID] |
| 1693 | for _, onu := range onugem { |
| 1694 | for _, gem := range onu.GemPorts { |
| 1695 | if gem == gemPortID { |
| 1696 | return onu.OnuID, nil |
| 1697 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1698 | } |
| 1699 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1700 | log.Errorw("onuid is not found", log.Fields{"serialNumber": serialNumber, "intfId": intfID, "gemPort": gemPortID}) |
| 1701 | return uint32(0), errors.New("key error, onuid is not found") // ONU ID 0 is not a valid one |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1702 | } |
| 1703 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1704 | //GetLogicalPortFromPacketIn function computes logical port UNI/NNI port from packet-in indication and returns the same |
| 1705 | func (f *OpenOltFlowMgr) GetLogicalPortFromPacketIn(packetIn *openoltpb2.PacketIndication) (uint32, error) { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1706 | var logicalPortNum uint32 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1707 | var onuID uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1708 | var err error |
| 1709 | |
| 1710 | if packetIn.IntfType == "pon" { |
| 1711 | // packet indication does not have serial number , so sending as nil |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1712 | if onuID, err = f.getOnuIDfromGemPortMap("", packetIn.IntfId, packetIn.GemportId); err != nil { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1713 | log.Errorw("Unable to get ONU ID from GEM/PON port", log.Fields{"pon port": packetIn.IntfId, "gemport": packetIn.GemportId}) |
| 1714 | return logicalPortNum, err |
| 1715 | } |
| 1716 | if packetIn.PortNo != 0 { |
| 1717 | logicalPortNum = packetIn.PortNo |
| 1718 | } else { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1719 | uniID := uint32(0) // FIXME - multi-uni support |
| 1720 | logicalPortNum = MkUniPortNum(packetIn.IntfId, onuID, uniID) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1721 | } |
| 1722 | // Store the gem port through which the packet_in came. Use the same gem port for packet_out |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1723 | f.UpdateGemPortForPktIn(packetIn.IntfId, onuID, logicalPortNum, packetIn.GemportId) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1724 | } else if packetIn.IntfType == "nni" { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1725 | logicalPortNum = IntfIDToPortNo(packetIn.IntfId, voltha.Port_ETHERNET_NNI) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1726 | } |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 1727 | log.Debugw("Retrieved logicalport from packet-in", log.Fields{ |
| 1728 | "logicalPortNum": logicalPortNum, |
| 1729 | "IntfType": packetIn.IntfType, |
| 1730 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 1731 | }) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1732 | return logicalPortNum, nil |
| 1733 | } |
| 1734 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1735 | //GetPacketOutGemPortID returns gemPortId |
| 1736 | func (f *OpenOltFlowMgr) GetPacketOutGemPortID(intfID uint32, onuID uint32, portNum uint32) (uint32, error) { |
| 1737 | var gemPortID uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1738 | var err error |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1739 | |
| 1740 | f.lockCache.Lock() |
| 1741 | defer f.lockCache.Unlock() |
| 1742 | pktInkey := rsrcMgr.PacketInInfoKey{IntfID: intfID, OnuID: onuID, LogicalPort: portNum} |
| 1743 | |
| 1744 | gemPortID, ok := f.packetInGemPort[pktInkey] |
| 1745 | if ok { |
| 1746 | log.Debugw("Found gemport for pktin key", log.Fields{"pktinkey": pktInkey, "gem": gemPortID}) |
| 1747 | return gemPortID, err |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1748 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1749 | //If gem is not found in cache try to get it from kv store, if found in kv store, update the cache and return. |
| 1750 | gemPortID, err = f.resourceMgr.GetGemPortFromOnuPktIn(intfID, onuID, portNum) |
| 1751 | if err == nil { |
| 1752 | if gemPortID != 0 { |
| 1753 | f.packetInGemPort[pktInkey] = gemPortID |
| 1754 | log.Debugw("Found gem port from kv store and updating cache with gemport", |
| 1755 | log.Fields{"pktinkey": pktInkey, "gem": gemPortID}) |
| 1756 | return gemPortID, nil |
| 1757 | } |
| 1758 | } |
| 1759 | log.Errorw("Failed to get gemport", log.Fields{"pktinkey": pktInkey, "gem": gemPortID}) |
| 1760 | return uint32(0), err |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1761 | } |
| 1762 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1763 | func installFlowOnAllGemports( |
| 1764 | f1 func(intfId uint32, onuId uint32, uniId uint32, |
| 1765 | portNo uint32, classifier map[string]interface{}, action map[string]interface{}, |
| 1766 | logicalFlow *ofp.OfpFlowStats, allocId uint32, gemPortId uint32), |
| 1767 | f2 func(intfId uint32, onuId uint32, uniId uint32, portNo uint32, |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1768 | logicalFlow *ofp.OfpFlowStats, allocId uint32, gemPortId uint32, vlanId uint32, |
| 1769 | classifier map[string]interface{}, action map[string]interface{}), |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1770 | args map[string]uint32, |
| 1771 | classifier map[string]interface{}, action map[string]interface{}, |
| 1772 | logicalFlow *ofp.OfpFlowStats, |
| 1773 | gemPorts []uint32, |
| 1774 | FlowType string, |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1775 | vlanID ...uint32) { |
| 1776 | log.Debugw("Installing flow on all GEM ports", log.Fields{"FlowType": FlowType, "gemPorts": gemPorts, "vlan": vlanID}) |
| 1777 | for _, gemPortID := range gemPorts { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1778 | if FlowType == HsiaFlow || FlowType == DhcpFlow { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1779 | f1(args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1780 | } else if FlowType == EapolFlow { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1781 | f2(args["intfId"], args["onuId"], args["uniId"], args["portNo"], logicalFlow, args["allocId"], gemPortID, vlanID[0], classifier, action) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1782 | } else { |
| 1783 | log.Errorw("Unrecognized Flow Type", log.Fields{"FlowType": FlowType}) |
| 1784 | return |
| 1785 | } |
| 1786 | } |
| 1787 | } |
| 1788 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1789 | func (f *OpenOltFlowMgr) addDHCPTrapFlowOnNNI(logicalFlow *ofp.OfpFlowStats, classifier map[string]interface{}, portNo uint32) { |
| 1790 | log.Debug("Adding trap-dhcp-of-nni-flow") |
| 1791 | action := make(map[string]interface{}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1792 | classifier[PacketTagType] = DoubleTag |
| 1793 | action[TrapToHost] = true |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1794 | var err error |
| 1795 | var networkInterfaceID uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1796 | /* We manage flowId resource pool on per PON port basis. |
| 1797 | Since this situation is tricky, as a hack, we pass the NNI port |
| 1798 | index (network_intf_id) as PON port Index for the flowId resource |
| 1799 | pool. Also, there is no ONU Id available for trapping DHCP packets |
| 1800 | on NNI port, use onu_id as -1 (invalid) |
| 1801 | ****************** CAVEAT ******************* |
| 1802 | This logic works if the NNI Port Id falls within the same valid |
| 1803 | range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 1804 | we need to have a re-look at this. |
| 1805 | ********************************************* |
| 1806 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1807 | onuID := -1 |
| 1808 | uniID := -1 |
| 1809 | gemPortID := -1 |
| 1810 | allocID := -1 |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1811 | networkInterfaceID, err = getNniIntfID(classifier, action) |
| 1812 | if err != nil { |
| 1813 | log.Error("Failed to get nniIntf ID") |
| 1814 | return |
| 1815 | } |
| 1816 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1817 | flowStoreCookie := getFlowStoreCookie(classifier, uint32(0)) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1818 | if present := f.resourceMgr.IsFlowCookieOnKVStore(uint32(networkInterfaceID), int32(onuID), int32(uniID), flowStoreCookie); present { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1819 | log.Debug("Flow-exists--not-re-adding") |
| 1820 | return |
| 1821 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1822 | flowID, err := f.resourceMgr.GetFlowID(uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1823 | if err != nil { |
| 1824 | log.Errorw("Flow id unavailable for DHCP traponNNI flow", log.Fields{"error": err}) |
| 1825 | return |
| 1826 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1827 | var classifierProto *openoltpb2.Classifier |
| 1828 | var actionProto *openoltpb2.Action |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1829 | if classifierProto = makeOpenOltClassifierField(classifier); classifierProto == nil { |
| 1830 | log.Error("Error in making classifier protobuf for dhcp trap on nni flow") |
| 1831 | return |
| 1832 | } |
| 1833 | log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto}) |
| 1834 | if actionProto = makeOpenOltActionField(action); actionProto == nil { |
| 1835 | log.Error("Error in making action protobuf for dhcp trap on nni flow") |
| 1836 | return |
| 1837 | } |
| 1838 | log.Debugw("Created action proto", log.Fields{"action": *actionProto}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1839 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 1840 | OnuId: int32(onuID), // OnuId not required |
| 1841 | UniId: int32(uniID), // UniId not used |
| 1842 | FlowId: flowID, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1843 | FlowType: Downstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1844 | AllocId: int32(allocID), // AllocId not used |
| 1845 | NetworkIntfId: int32(networkInterfaceID), |
| 1846 | GemportId: int32(gemPortID), // GemportId not used |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1847 | Classifier: classifierProto, |
| 1848 | Action: actionProto, |
| 1849 | Priority: int32(logicalFlow.Priority), |
| 1850 | Cookie: logicalFlow.Cookie, |
| 1851 | PortNo: portNo} |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1852 | if ok := f.addFlowToDevice(logicalFlow, &downstreamflow); ok { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1853 | log.Debug("DHCP trap on NNI flow added to device successfully") |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1854 | flowsToKVStore := f.getUpdatedFlowInfo(&downstreamflow, flowStoreCookie, "", flowID, logicalFlow.Id) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1855 | if err := f.updateFlowInfoToKVStore(int32(networkInterfaceID), |
| 1856 | int32(onuID), |
| 1857 | int32(uniID), |
| 1858 | flowID, flowsToKVStore); err != nil { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 1859 | log.Errorw("Error uploading DHCP DL flow into KV store", log.Fields{"flow": downstreamflow, "error": err}) |
| 1860 | } |
| 1861 | } |
| 1862 | return |
| 1863 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1864 | |
| 1865 | func verifyMeterIDAndGetDirection(MeterID uint32, Dir tp_pb.Direction) (string, error) { |
| 1866 | if MeterID == 0 { // This should never happen |
| 1867 | log.Error("Invalid meter id") |
| 1868 | return "", errors.New("invalid meter id") |
| 1869 | } |
| 1870 | if Dir == tp_pb.Direction_UPSTREAM { |
| 1871 | return "upstream", nil |
| 1872 | } else if Dir == tp_pb.Direction_DOWNSTREAM { |
| 1873 | return "downstream", nil |
| 1874 | } |
| 1875 | return "", nil |
| 1876 | } |
| 1877 | |
| 1878 | func (f *OpenOltFlowMgr) checkAndAddFlow(args map[string]uint32, classifierInfo map[string]interface{}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1879 | actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpInst *tp.TechProfile, gemPorts []uint32, |
| 1880 | TpID uint32, uni string) { |
| 1881 | var gemPort uint32 |
| 1882 | intfID := args[IntfID] |
| 1883 | onuID := args[OnuID] |
| 1884 | uniID := args[UniID] |
| 1885 | portNo := args[PortNo] |
| 1886 | allocID := TpInst.UsScheduler.AllocID |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1887 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 1888 | if ipProto.(uint32) == IPProtoDhcp { |
| 1889 | log.Info("Adding DHCP flow") |
| 1890 | if pcp, ok := classifierInfo[VlanPcp]; ok { |
| 1891 | gemPort = f.techprofile[intfID].GetGemportIDForPbit(TpInst, |
| 1892 | tp_pb.Direction_UPSTREAM, |
| 1893 | pcp.(uint32)) |
| 1894 | //Adding DHCP upstream flow |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1895 | f.addDHCPTrapFlow(intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1896 | } else { |
| 1897 | //Adding DHCP upstream flow to all gemports |
| 1898 | installFlowOnAllGemports(f.addDHCPTrapFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, DhcpFlow) |
| 1899 | } |
| 1900 | |
| 1901 | } else if ipProto == IgmpProto { |
| 1902 | log.Info("igmp flow add ignored, not implemented yet") |
| 1903 | return |
| 1904 | } else { |
| 1905 | log.Errorw("Invalid-Classifier-to-handle", log.Fields{"classifier": classifierInfo, "action": actionInfo}) |
| 1906 | return |
| 1907 | } |
| 1908 | } else if ethType, ok := classifierInfo[EthType]; ok { |
| 1909 | if ethType.(uint32) == EapEthType { |
| 1910 | log.Info("Adding EAPOL flow") |
| 1911 | var vlanID uint32 |
| 1912 | if val, ok := classifierInfo[VlanVid]; ok { |
| 1913 | vlanID = (val.(uint32)) & VlanvIDMask |
| 1914 | } else { |
| 1915 | vlanID = DefaultMgmtVlan |
| 1916 | } |
| 1917 | if pcp, ok := classifierInfo[VlanPcp]; ok { |
| 1918 | gemPort = f.techprofile[intfID].GetGemportIDForPbit(TpInst, |
| 1919 | tp_pb.Direction_UPSTREAM, |
| 1920 | pcp.(uint32)) |
| 1921 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1922 | f.addEAPOLFlow(intfID, onuID, uniID, portNo, flow, allocID, gemPort, vlanID, classifierInfo, actionInfo) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1923 | } else { |
| 1924 | installFlowOnAllGemports(nil, f.addEAPOLFlow, args, classifierInfo, actionInfo, flow, gemPorts, EapolFlow, vlanID) |
| 1925 | } |
| 1926 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1927 | } else if _, ok := actionInfo[PushVlan]; ok { |
| 1928 | log.Info("Adding upstream data rule") |
| 1929 | if pcp, ok := classifierInfo[VlanPcp]; ok { |
| 1930 | gemPort = f.techprofile[intfID].GetGemportIDForPbit(TpInst, |
| 1931 | tp_pb.Direction_UPSTREAM, |
| 1932 | pcp.(uint32)) |
| 1933 | //Adding HSIA upstream flow |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1934 | f.addUpstreamDataFlow(intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1935 | } else { |
| 1936 | //Adding HSIA upstream flow to all gemports |
| 1937 | installFlowOnAllGemports(f.addUpstreamDataFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, HsiaFlow) |
| 1938 | } |
| 1939 | } else if _, ok := actionInfo[PopVlan]; ok { |
| 1940 | log.Info("Adding Downstream data rule") |
| 1941 | if pcp, ok := classifierInfo[VlanPcp]; ok { |
| 1942 | gemPort = f.techprofile[intfID].GetGemportIDForPbit(TpInst, |
aishwaryarana01 | d9f985f | 2019-09-03 15:41:40 -0500 | [diff] [blame] | 1943 | tp_pb.Direction_DOWNSTREAM, |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1944 | pcp.(uint32)) |
| 1945 | //Adding HSIA downstream flow |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1946 | f.addDownstreamDataFlow(intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 1947 | } else { |
| 1948 | //Adding HSIA downstream flow to all gemports |
| 1949 | installFlowOnAllGemports(f.addDownstreamDataFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, HsiaFlow) |
| 1950 | } |
| 1951 | } else { |
| 1952 | log.Errorw("Invalid-flow-type-to-handle", log.Fields{"classifier": classifierInfo, "action": actionInfo, "flow": flow}) |
| 1953 | return |
| 1954 | } |
| 1955 | // Send Techprofile download event to child device in go routine as it takes time |
| 1956 | go f.sendTPDownloadMsgToChild(intfID, onuID, uniID, uni, TpID) |
| 1957 | } |
| 1958 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1959 | func (f *OpenOltFlowMgr) isGemPortUsedByAnotherFlow(gemPK gemPortKey) bool { |
| 1960 | flowIDList := f.flowsUsedByGemPort[gemPK] |
| 1961 | if len(flowIDList) > 1 { |
| 1962 | return true |
| 1963 | } |
| 1964 | return false |
| 1965 | } |
| 1966 | |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 1967 | func (f *OpenOltFlowMgr) isTechProfileUsedByAnotherGem(ponIntf uint32, onuID uint32, uniID uint32, tpID uint32, tpInst *tp.TechProfile, gemPortID uint32) (bool, uint32) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1968 | currentGemPorts := f.resourceMgr.GetCurrentGEMPortIDsForOnu(ponIntf, onuID, uniID) |
| 1969 | tpGemPorts := tpInst.UpstreamGemPortAttributeList |
| 1970 | for _, currentGemPort := range currentGemPorts { |
| 1971 | for _, tpGemPort := range tpGemPorts { |
| 1972 | if (currentGemPort == tpGemPort.GemportID) && (currentGemPort != gemPortID) { |
| 1973 | return true, currentGemPort |
| 1974 | } |
| 1975 | } |
| 1976 | } |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 1977 | if tpInst.InstanceCtrl.Onu == "single-instance" { |
| 1978 | // The TP information for the given TP ID, PON ID, ONU ID, UNI ID should be removed. |
| 1979 | f.resourceMgr.RemoveTechProfileIDForOnu(ponIntf, uint32(onuID), uint32(uniID), tpID) |
| 1980 | f.DeleteTechProfileInstance(ponIntf, uint32(onuID), uint32(uniID), "", tpID) |
| 1981 | |
| 1982 | // Although we cleaned up TP Instance for the given (PON ID, ONU ID, UNI ID), the TP might |
| 1983 | // still be used on other uni ports. |
| 1984 | // So, we need to check and make sure that no other gem port is referring to the given TP ID |
| 1985 | // on any other uni port. |
| 1986 | tpInstances := f.techprofile[ponIntf].FindAllTpInstances(tpID, ponIntf, onuID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1987 | log.Debugw("got single instance tp instances", log.Fields{"tpInstances": tpInstances}) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 1988 | for i := 0; i < len(tpInstances); i++ { |
| 1989 | tpI := tpInstances[i] |
| 1990 | tpGemPorts := tpI.UpstreamGemPortAttributeList |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1991 | for _, tpGemPort := range tpGemPorts { |
| 1992 | if tpGemPort.GemportID != gemPortID { |
| 1993 | log.Debugw("single instance tp is in use by gem", log.Fields{"gemPort": tpGemPort.GemportID}) |
| 1994 | return true, tpGemPort.GemportID |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 1995 | } |
| 1996 | } |
| 1997 | } |
| 1998 | } |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1999 | log.Debug("tech profile is not in use by any gem") |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2000 | return false, 0 |
| 2001 | } |
| 2002 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2003 | func formulateClassifierInfoFromFlow(classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2004 | for _, field := range flows.GetOfbFields(flow) { |
| 2005 | if field.Type == flows.ETH_TYPE { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2006 | classifierInfo[EthType] = field.GetEthType() |
| 2007 | log.Debug("field-type-eth-type", log.Fields{"classifierInfo[ETH_TYPE]": classifierInfo[EthType].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2008 | } else if field.Type == flows.IP_PROTO { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2009 | classifierInfo[IPProto] = field.GetIpProto() |
| 2010 | 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] | 2011 | } else if field.Type == flows.IN_PORT { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2012 | classifierInfo[InPort] = field.GetPort() |
| 2013 | 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] | 2014 | } else if field.Type == flows.VLAN_VID { |
Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 2015 | classifierInfo[VlanVid] = field.GetVlanVid() & 0xfff |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2016 | 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] | 2017 | } else if field.Type == flows.VLAN_PCP { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2018 | classifierInfo[VlanPcp] = field.GetVlanPcp() |
| 2019 | 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] | 2020 | } else if field.Type == flows.UDP_DST { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2021 | classifierInfo[UDPDst] = field.GetUdpDst() |
| 2022 | 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] | 2023 | } else if field.Type == flows.UDP_SRC { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2024 | classifierInfo[UDPSrc] = field.GetUdpSrc() |
| 2025 | 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] | 2026 | } else if field.Type == flows.IPV4_DST { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2027 | classifierInfo[Ipv4Dst] = field.GetIpv4Dst() |
| 2028 | 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] | 2029 | } else if field.Type == flows.IPV4_SRC { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2030 | classifierInfo[Ipv4Src] = field.GetIpv4Src() |
| 2031 | 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] | 2032 | } else if field.Type == flows.METADATA { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2033 | classifierInfo[Metadata] = field.GetTableMetadata() |
| 2034 | log.Debug("field-type-metadata", log.Fields{"classifierInfo[Metadata]": classifierInfo[Metadata].(uint64)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2035 | } else if field.Type == flows.TUNNEL_ID { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2036 | classifierInfo[TunnelID] = field.GetTunnelId() |
| 2037 | log.Debug("field-type-tunnelId", log.Fields{"classifierInfo[TUNNEL_ID]": classifierInfo[TunnelID].(uint64)}) |
| 2038 | } else { |
| 2039 | log.Errorw("Un supported field type", log.Fields{"type": field.Type}) |
| 2040 | return |
| 2041 | } |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | func formulateActionInfoFromFlow(actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2046 | for _, action := range flows.GetActions(flow) { |
| 2047 | if action.Type == flows.OUTPUT { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2048 | if out := action.GetOutput(); out != nil { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2049 | actionInfo[Output] = out.GetPort() |
| 2050 | log.Debugw("action-type-output", log.Fields{"out_port": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2051 | } else { |
| 2052 | log.Error("Invalid output port in action") |
| 2053 | return errors.New("invalid output port in action") |
| 2054 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2055 | } else if action.Type == flows.POP_VLAN { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2056 | actionInfo[PopVlan] = true |
| 2057 | 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] | 2058 | } else if action.Type == flows.PUSH_VLAN { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2059 | if out := action.GetPush(); out != nil { |
| 2060 | if tpid := out.GetEthertype(); tpid != 0x8100 { |
| 2061 | log.Errorw("Invalid ethertype in push action", log.Fields{"ethertype": actionInfo[PushVlan].(int32)}) |
| 2062 | } else { |
| 2063 | actionInfo[PushVlan] = true |
| 2064 | actionInfo[TPID] = tpid |
| 2065 | log.Debugw("action-type-push-vlan", |
| 2066 | log.Fields{"push_tpid": actionInfo[TPID].(uint32), "in_port": classifierInfo[InPort].(uint32)}) |
| 2067 | } |
| 2068 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2069 | } else if action.Type == flows.SET_FIELD { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2070 | if out := action.GetSetField(); out != nil { |
| 2071 | if field := out.GetField(); field != nil { |
| 2072 | if ofClass := field.GetOxmClass(); ofClass != ofp.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
| 2073 | log.Errorw("Invalid openflow class", log.Fields{"class": ofClass}) |
| 2074 | return errors.New("invalid openflow class") |
| 2075 | } |
| 2076 | /*log.Debugw("action-type-set-field",log.Fields{"field": field, "in_port": classifierInfo[IN_PORT].(uint32)})*/ |
| 2077 | if ofbField := field.GetOfbField(); ofbField != nil { |
| 2078 | if fieldtype := ofbField.GetType(); fieldtype == ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
| 2079 | if vlan := ofbField.GetVlanVid(); vlan != 0 { |
| 2080 | actionInfo[VlanVid] = vlan & 0xfff |
| 2081 | log.Debugw("action-set-vlan-vid", log.Fields{"actionInfo[VLAN_VID]": actionInfo[VlanVid].(uint32)}) |
| 2082 | } else { |
| 2083 | log.Error("No Invalid vlan id in set vlan-vid action") |
| 2084 | } |
| 2085 | } else { |
| 2086 | log.Errorw("unsupported-action-set-field-type", log.Fields{"type": fieldtype}) |
| 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | } else { |
| 2092 | log.Errorw("Un supported action type", log.Fields{"type": action.Type}) |
| 2093 | return errors.New("un supported action type") |
| 2094 | } |
| 2095 | } |
| 2096 | return nil |
| 2097 | } |
| 2098 | |
| 2099 | func formulateControllerBoundTrapFlowInfo(actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2100 | if isControllerFlow := IsControllerBoundFlow(actionInfo[Output].(uint32)); isControllerFlow { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2101 | log.Debug("Controller bound trap flows, getting inport from tunnelid") |
| 2102 | /* Get UNI port/ IN Port from tunnel ID field for upstream controller bound flows */ |
| 2103 | if portType := IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2104 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2105 | classifierInfo[InPort] = uniPort |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2106 | 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] | 2107 | } else { |
| 2108 | log.Error("upstream pon-to-controller-flow, NO-inport-in-tunnelid") |
| 2109 | return errors.New("upstream pon-to-controller-flow, NO-inport-in-tunnelid") |
| 2110 | } |
| 2111 | } |
| 2112 | } else { |
| 2113 | log.Debug("Non-Controller flows, getting uniport from tunnelid") |
| 2114 | // 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] | 2115 | if portType := IntfIDToPortTypeName(actionInfo[Output].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2116 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2117 | actionInfo[Output] = uniPort |
| 2118 | 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] | 2119 | } else { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2120 | log.Debug("downstream-nni-to-pon-port-flow, no-outport-in-tunnelid", log.Fields{"InPort": classifierInfo[InPort].(uint32), "outPort": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2121 | return errors.New("downstream-nni-to-pon-port-flow, no-outport-in-tunnelid") |
| 2122 | } |
| 2123 | // Upstream flow from PON to NNI port , Use tunnel ID as new IN port / UNI port |
| 2124 | } else if portType := IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2125 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2126 | classifierInfo[InPort] = uniPort |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2127 | log.Debugw("upstream-pon-to-nni-port-flow, inport-in-tunnelid", log.Fields{"newInPort": actionInfo[Output].(uint32), |
| 2128 | "outport": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2129 | } else { |
| 2130 | log.Debug("upstream-pon-to-nni-port-flow, no-inport-in-tunnelid", log.Fields{"InPort": classifierInfo[InPort].(uint32), |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2131 | "outPort": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2132 | return errors.New("upstream-pon-to-nni-port-flow, no-inport-in-tunnelid") |
| 2133 | } |
| 2134 | } |
| 2135 | } |
| 2136 | return nil |
| 2137 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2138 | |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2139 | func getTpIDFromFlow(flow *ofp.OfpFlowStats) (uint32, error) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2140 | /* Metadata 8 bytes: |
| 2141 | Most Significant 2 Bytes = Inner VLAN |
| 2142 | Next 2 Bytes = Tech Profile ID(TPID) |
| 2143 | Least Significant 4 Bytes = Port ID |
| 2144 | Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 2145 | subscriber related flows. |
| 2146 | */ |
| 2147 | metadata := flows.GetMetadataFromWriteMetadataAction(flow) |
| 2148 | if metadata == 0 { |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2149 | log.Error("metadata-is-not-present-in-flow-which-is-mandatory") |
| 2150 | return 0, errors.New("metadata-is-not-present-in-flow-which-is-mandatory") |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2151 | } |
| 2152 | TpID := flows.GetTechProfileIDFromWriteMetaData(metadata) |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2153 | return uint32(TpID), nil |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | func appendUnique(slice []uint32, item uint32) []uint32 { |
| 2157 | for _, sliceElement := range slice { |
| 2158 | if sliceElement == item { |
| 2159 | return slice |
| 2160 | } |
| 2161 | } |
| 2162 | return append(slice, item) |
| 2163 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2164 | |
| 2165 | // getNniIntfID gets nni intf id from the flow classifier/action |
| 2166 | func getNniIntfID(classifier map[string]interface{}, action map[string]interface{}) (uint32, error) { |
| 2167 | |
| 2168 | portType := IntfIDToPortTypeName(classifier[InPort].(uint32)) |
| 2169 | if portType == voltha.Port_PON_OLT { |
| 2170 | intfID := IntfIDFromNniPortNum(action[Output].(uint32)) |
| 2171 | log.Debugw("output Nni IntfID is", log.Fields{"intfid": intfID}) |
| 2172 | return intfID, nil |
| 2173 | } else if portType == voltha.Port_ETHERNET_NNI { |
| 2174 | intfID := IntfIDFromNniPortNum(classifier[InPort].(uint32)) |
| 2175 | log.Debugw("input Nni IntfID is", log.Fields{"intfid": intfID}) |
| 2176 | return intfID, nil |
| 2177 | } |
| 2178 | return uint32(0), nil |
| 2179 | } |
| 2180 | |
| 2181 | // UpdateGemPortForPktIn updates gemport for packet-in in to the cache and to the kv store as well. |
| 2182 | func (f *OpenOltFlowMgr) UpdateGemPortForPktIn(intfID uint32, onuID uint32, logicalPort uint32, gemPort uint32) { |
| 2183 | pktInkey := rsrcMgr.PacketInInfoKey{IntfID: intfID, OnuID: onuID, LogicalPort: logicalPort} |
| 2184 | |
| 2185 | f.lockCache.Lock() |
| 2186 | defer f.lockCache.Unlock() |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame^] | 2187 | lookupGemPort, ok := f.packetInGemPort[pktInkey] |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2188 | if ok { |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame^] | 2189 | if lookupGemPort == gemPort { |
| 2190 | log.Debugw("pktin key/value found in cache , no need to update kv as we are assuming both will be in sync", |
| 2191 | log.Fields{"pktinkey": pktInkey, "gem": gemPort}) |
| 2192 | return |
| 2193 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2194 | } |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame^] | 2195 | f.packetInGemPort[pktInkey] = gemPort |
| 2196 | |
| 2197 | f.resourceMgr.UpdateGemPortForPktIn(pktInkey, gemPort) |
| 2198 | 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] | 2199 | return |
| 2200 | } |
| 2201 | |
| 2202 | // AddUniPortToOnuInfo adds uni port to the onugem info both in cache and kvstore. |
| 2203 | func (f *OpenOltFlowMgr) AddUniPortToOnuInfo(intfID uint32, onuID uint32, portNum uint32) { |
| 2204 | |
| 2205 | f.lockCache.Lock() |
| 2206 | defer f.lockCache.Unlock() |
| 2207 | onugem := f.onuGemInfo[intfID] |
| 2208 | for idx, onu := range onugem { |
| 2209 | if onu.OnuID == onuID { |
| 2210 | for _, uni := range onu.UniPorts { |
|