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