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