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 | |
| 17 | package adaptercore |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "crypto/md5" |
| 22 | "encoding/json" |
| 23 | "errors" |
| 24 | "fmt" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 25 | "github.com/opencord/voltha-go/common/log" |
| 26 | tp "github.com/opencord/voltha-go/common/techprofile" |
| 27 | fd "github.com/opencord/voltha-go/rw_core/flow_decomposition" |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 28 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager" |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 29 | ic "github.com/opencord/voltha-protos/go/inter_container" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 30 | ofp "github.com/opencord/voltha-protos/go/openflow_13" |
| 31 | openolt_pb2 "github.com/opencord/voltha-protos/go/openolt" |
| 32 | voltha "github.com/opencord/voltha-protos/go/voltha" |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 33 | "math/big" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 34 | ) |
| 35 | |
| 36 | const ( |
| 37 | // Flow categories |
| 38 | HSIA_FLOW = "HSIA_FLOW" |
| 39 | EAPOL_FLOW = "EAPOL_FLOW" |
| 40 | |
| 41 | IP_PROTO_DHCP = 17 |
| 42 | |
| 43 | IP_PROTO_IGMP = 2 |
| 44 | |
| 45 | EAP_ETH_TYPE = 0x888e |
| 46 | LLDP_ETH_TYPE = 0x88cc |
| 47 | |
| 48 | IGMP_PROTO = 2 |
| 49 | |
| 50 | //FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py |
| 51 | DEFAULT_MGMT_VLAN = 4091 |
| 52 | |
| 53 | DEFAULT_NETWORK_INTERFACE_ID = 0 |
| 54 | |
| 55 | // Openolt Flow |
| 56 | UPSTREAM = "upstream" |
| 57 | DOWNSTREAM = "downstream" |
| 58 | PACKET_TAG_TYPE = "pkt_tag_type" |
| 59 | UNTAGGED = "untagged" |
| 60 | SINGLE_TAG = "single_tag" |
| 61 | DOUBLE_TAG = "double_tag" |
| 62 | |
| 63 | // classifierInfo |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 64 | ETH_TYPE = "eth_type" |
| 65 | TPID = "tpid" |
| 66 | IP_PROTO = "ip_proto" |
| 67 | IN_PORT = "in_port" |
| 68 | VLAN_VID = "vlan_vid" |
| 69 | VLAN_PCP = "vlan_pcp" |
| 70 | UDP_DST = "udp_dst" |
| 71 | UDP_SRC = "udp_src" |
| 72 | IPV4_DST = "ipv4_dst" |
| 73 | IPV4_SRC = "ipv4_src" |
| 74 | METADATA = "metadata" |
| 75 | TUNNEL_ID = "tunnel_id" |
| 76 | OUTPUT = "output" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 77 | // Action |
| 78 | POP_VLAN = "pop_vlan" |
| 79 | PUSH_VLAN = "push_vlan" |
| 80 | TRAP_TO_HOST = "trap_to_host" |
| 81 | ) |
| 82 | |
| 83 | type OpenOltFlowMgr struct { |
| 84 | techprofile []*tp.TechProfileMgr |
| 85 | deviceHandler *DeviceHandler |
| 86 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 87 | } |
| 88 | |
| 89 | func NewFlowManager(dh *DeviceHandler, rsrcMgr *rsrcMgr.OpenOltResourceMgr) *OpenOltFlowMgr { |
| 90 | log.Info("Initializing flow manager") |
| 91 | var flowMgr OpenOltFlowMgr |
| 92 | flowMgr.deviceHandler = dh |
| 93 | flowMgr.resourceMgr = rsrcMgr |
| 94 | if err := flowMgr.populateTechProfilePerPonPort(); err != nil { |
| 95 | log.Error("Error while populating tech profile mgr\n") |
| 96 | return nil |
| 97 | } |
| 98 | log.Info("Initialization of flow manager success!!") |
| 99 | return &flowMgr |
| 100 | } |
| 101 | |
| 102 | func (f *OpenOltFlowMgr) divideAndAddFlow(intfId uint32, onuId uint32, uniId uint32, portNo uint32, classifierInfo map[string]interface{}, actionInfo map[string]interface{}, flow *ofp.OfpFlowStats) { |
| 103 | var allocId []uint32 |
| 104 | var gemPorts []uint32 |
| 105 | |
| 106 | log.Infow("Dividing flow", log.Fields{"intfId": intfId, "onuId": onuId, "uniId": uniId, "portNo": portNo, "classifier": classifierInfo, "action": actionInfo}) |
| 107 | |
| 108 | log.Infow("sorting flow", log.Fields{"intfId": intfId, "onuId": onuId, "uniId": uniId, "portNo": portNo, |
| 109 | "classifierInfo": classifierInfo, "actionInfo": actionInfo}) |
| 110 | |
| 111 | uni := getUniPortPath(intfId, onuId, uniId) |
| 112 | log.Debugw("Uni port name", log.Fields{"uni": uni}) |
| 113 | allocId, gemPorts = f.createTcontGemports(intfId, onuId, uniId, uni, portNo, flow.GetTableId()) |
| 114 | if allocId == nil || gemPorts == nil { |
| 115 | log.Error("alloc-id-gem-ports-unavailable") |
| 116 | return |
| 117 | } |
| 118 | |
| 119 | /* Flows can't be added specific to gemport unless p-bits are received. |
| 120 | * Hence adding flows for all gemports |
| 121 | */ |
| 122 | for _, gemPort := range gemPorts { |
| 123 | if ipProto, ok := classifierInfo[IP_PROTO]; ok { |
| 124 | if ipProto.(uint32) == IP_PROTO_DHCP { |
| 125 | log.Info("Adding DHCP flow") |
| 126 | f.addDHCPTrapFlow(intfId, onuId, uniId, portNo, classifierInfo, actionInfo, flow, allocId[0], gemPort) |
| 127 | } else if ipProto == IP_PROTO_IGMP { |
| 128 | log.Info("igmp flow add ignored, not implemented yet") |
| 129 | } else { |
| 130 | log.Errorw("Invalid-Classifier-to-handle", log.Fields{"classifier": classifierInfo, "action": actionInfo}) |
| 131 | //return errors.New("Invalid-Classifier-to-handle") |
| 132 | } |
| 133 | } else if ethType, ok := classifierInfo[ETH_TYPE]; ok { |
| 134 | if ethType.(uint32) == EAP_ETH_TYPE { |
| 135 | log.Info("Adding EAPOL flow") |
| 136 | f.addEAPOLFlow(intfId, onuId, uniId, portNo, flow, allocId[0], gemPort, DEFAULT_MGMT_VLAN) |
| 137 | if vlan := getSubscriberVlan(fd.GetInPort(flow)); vlan != 0 { |
| 138 | f.addEAPOLFlow(intfId, onuId, uniId, portNo, flow, allocId[0], gemPort, vlan) |
| 139 | } |
| 140 | // Send Techprofile download event to child device in go routine as it takes time |
| 141 | go f.sendTPDownloadMsgToChild(intfId, onuId, uniId, uni) |
| 142 | } |
| 143 | if ethType == LLDP_ETH_TYPE { |
| 144 | log.Info("Adding LLDP flow") |
| 145 | addLLDPFlow(flow, portNo) |
| 146 | } |
| 147 | } else if _, ok := actionInfo[PUSH_VLAN]; ok { |
| 148 | log.Info("Adding upstream data rule") |
| 149 | f.addUpstreamDataFlow(intfId, onuId, uniId, portNo, classifierInfo, actionInfo, flow, allocId[0], gemPort) |
| 150 | } else if _, ok := actionInfo[POP_VLAN]; ok { |
| 151 | log.Info("Adding Downstream data rule") |
| 152 | f.addDownstreamDataFlow(intfId, onuId, uniId, portNo, classifierInfo, actionInfo, flow, allocId[0], gemPort) |
| 153 | } else { |
| 154 | log.Errorw("Invalid-flow-type-to-handle", log.Fields{"classifier": classifierInfo, "action": actionInfo, "flow": flow}) |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // This function allocates tconts and GEM ports for an ONU, currently one TCONT is supported per ONU |
| 160 | func (f *OpenOltFlowMgr) createTcontGemports(intfId uint32, onuId uint32, uniId uint32, uni string, uniPort uint32, tableID uint32) ([]uint32, []uint32) { |
| 161 | var allocID []uint32 |
| 162 | var gemPortIDs []uint32 |
| 163 | //If we already have allocated earlier for this onu, render them |
Abhilash S.L | 8ee9071 | 2019-04-29 16:24:22 +0530 | [diff] [blame] | 164 | if tcontId := f.resourceMgr.GetCurrentAllocIDForOnu(intfId, onuId, uniId); tcontId != 0 { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 165 | allocID = append(allocID, tcontId) |
| 166 | } |
| 167 | gemPortIDs = f.resourceMgr.GetCurrentGEMPortIDsForOnu(intfId, onuId, uniId) |
| 168 | if len(allocID) != 0 && len(gemPortIDs) != 0 { |
| 169 | log.Debug("Rendered Tcont and GEM ports from resource manager", log.Fields{"intfId": intfId, "onuId": onuId, "uniPort": uniId, |
| 170 | "allocID": allocID, "gemPortIDs": gemPortIDs}) |
| 171 | return allocID, gemPortIDs |
| 172 | } |
| 173 | log.Debug("Creating New TConts and Gem ports", log.Fields{"pon": intfId, "onu": onuId, "uni": uniId}) |
| 174 | |
| 175 | //FIXME: If table id is <= 63 using 64 as table id |
| 176 | if tableID < tp.DEFAULT_TECH_PROFILE_TABLE_ID { |
| 177 | tableID = tp.DEFAULT_TECH_PROFILE_TABLE_ID |
| 178 | } |
| 179 | tpPath := f.getTPpath(intfId, uni) |
| 180 | // Check tech profile instance already exists for derived port name |
| 181 | tech_profile_instance, err := f.techprofile[intfId].GetTPInstanceFromKVStore(tableID, tpPath) |
| 182 | if err != nil { // This should not happen, something wrong in KV backend transaction |
| 183 | log.Errorw("Error in fetching tech profile instance from KV store", log.Fields{"tableID": tableID, "path": tpPath}) |
| 184 | return nil, nil |
| 185 | } |
| 186 | if tech_profile_instance == nil { |
| 187 | log.Info("Creating tech profile instance", log.Fields{"path": tpPath}) |
| 188 | tech_profile_instance = f.techprofile[intfId].CreateTechProfInstance(tableID, uni, intfId) |
| 189 | if tech_profile_instance == nil { |
| 190 | log.Error("Tech-profile-instance-creation-failed") |
| 191 | return nil, nil |
| 192 | } |
| 193 | } else { |
| 194 | log.Debugw("Tech-profile-instance-already-exist-for-given port-name", log.Fields{"uni": uni}) |
| 195 | } |
| 196 | // Get upstream and downstream scheduler protos |
| 197 | us_scheduler := f.techprofile[intfId].GetUsScheduler(tech_profile_instance) |
| 198 | ds_scheduler := f.techprofile[intfId].GetDsScheduler(tech_profile_instance) |
| 199 | // Get TCONTS protos |
| 200 | tconts := f.techprofile[intfId].GetTconts(tech_profile_instance, us_scheduler, ds_scheduler) |
| 201 | if len(tconts) == 0 { |
| 202 | log.Error("TCONTS not found ") |
| 203 | return nil, nil |
| 204 | } |
| 205 | log.Debugw("Sending Create tcont to device", |
| 206 | log.Fields{"onu": onuId, "uni": uniId, "portNo": "", "tconts": tconts}) |
| 207 | if _, err := f.deviceHandler.Client.CreateTconts(context.Background(), |
| 208 | &openolt_pb2.Tconts{IntfId: intfId, |
| 209 | OnuId: onuId, |
| 210 | UniId: uniId, |
| 211 | PortNo: uniPort, |
| 212 | Tconts: tconts}); err != nil { |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 213 | log.Errorw("Error while creating TCONT in device", log.Fields{"error": err}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 214 | return nil, nil |
| 215 | } |
| 216 | allocID = append(allocID, tech_profile_instance.UsScheduler.AllocID) |
| 217 | for _, gem := range tech_profile_instance.UpstreamGemPortAttributeList { |
| 218 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 219 | } |
| 220 | log.Debugw("Allocated Tcont and GEM ports", log.Fields{"allocID": allocID, "gemports": gemPortIDs}) |
| 221 | // Send Tconts and GEM ports to KV store |
| 222 | f.storeTcontsGEMPortsIntoKVStore(intfId, onuId, uniId, allocID, gemPortIDs) |
| 223 | return allocID, gemPortIDs |
| 224 | } |
| 225 | |
| 226 | func (f *OpenOltFlowMgr) storeTcontsGEMPortsIntoKVStore(intfId uint32, onuId uint32, uniId uint32, allocID []uint32, gemPortIDs []uint32) { |
| 227 | |
| 228 | log.Debugw("Storing allocated Tconts and GEM ports into KV store", |
| 229 | log.Fields{"intfId": intfId, "onuId": onuId, "uniId": uniId, "allocID": allocID, "gemPortIDs": gemPortIDs}) |
| 230 | /* Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV store */ |
| 231 | if err := f.resourceMgr.UpdateAllocIdsForOnu(intfId, onuId, uniId, allocID); err != nil { |
| 232 | log.Error("Errow while uploading allocID to KV store") |
| 233 | } |
| 234 | if err := f.resourceMgr.UpdateGEMPortIDsForOnu(intfId, onuId, uniId, gemPortIDs); err != nil { |
| 235 | log.Error("Errow while uploading GEMports to KV store") |
| 236 | } |
| 237 | if err := f.resourceMgr.UpdateGEMportsPonportToOnuMapOnKVStore(gemPortIDs, intfId, onuId, uniId); err != nil { |
| 238 | log.Error("Errow while uploading gemtopon map to KV store") |
| 239 | } |
| 240 | log.Debug("Stored tconts and GEM into KV store successfully") |
| 241 | } |
| 242 | |
| 243 | func (f *OpenOltFlowMgr) populateTechProfilePerPonPort() error { |
| 244 | for _, techRange := range f.resourceMgr.DevInfo.Ranges { |
| 245 | for intfId := range techRange.IntfIds { |
| 246 | f.techprofile = append(f.techprofile, f.resourceMgr.ResourceMgrs[uint32(intfId)].TechProfileMgr) |
| 247 | } |
| 248 | } |
| 249 | //Make sure we have as many tech_profiles as there are pon ports on the device |
| 250 | if len(f.techprofile) != int(f.resourceMgr.DevInfo.GetPonPorts()) { |
| 251 | log.Errorw("Error while populating techprofile", |
| 252 | log.Fields{"numofTech": len(f.techprofile), "numPonPorts": f.resourceMgr.DevInfo.GetPonPorts()}) |
| 253 | return errors.New("Error while populating techprofile mgrs") |
| 254 | } |
| 255 | log.Infow("Populated techprofile per ponport successfully", |
| 256 | log.Fields{"numofTech": len(f.techprofile), "numPonPorts": f.resourceMgr.DevInfo.GetPonPorts()}) |
| 257 | return nil |
| 258 | } |
| 259 | |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 260 | func (f *OpenOltFlowMgr) addUpstreamDataFlow(intfId uint32, onuId uint32, uniId uint32, |
| 261 | portNo uint32, uplinkClassifier map[string]interface{}, |
| 262 | uplinkAction map[string]interface{}, logicalFlow *ofp.OfpFlowStats, |
| 263 | allocId uint32, gemportId uint32) { |
| 264 | uplinkClassifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 265 | log.Debugw("Adding upstream data flow", log.Fields{"uplinkClassifier": uplinkClassifier, "uplinkAction": uplinkAction}) |
| 266 | f.addHSIAFlow(intfId, onuId, uniId, portNo, uplinkClassifier, uplinkAction, |
| 267 | UPSTREAM, logicalFlow, allocId, gemportId) |
| 268 | /* TODO: Install Secondary EAP on the subscriber vlan */ |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 269 | } |
| 270 | |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 271 | func (f *OpenOltFlowMgr) addDownstreamDataFlow(intfId uint32, onuId uint32, uniId uint32, |
| 272 | portNo uint32, downlinkClassifier map[string]interface{}, |
| 273 | downlinkAction map[string]interface{}, logicalFlow *ofp.OfpFlowStats, |
| 274 | allocId uint32, gemportId uint32) { |
| 275 | downlinkClassifier[PACKET_TAG_TYPE] = DOUBLE_TAG |
| 276 | log.Debugw("Adding downstream data flow", log.Fields{"downlinkClassifier": downlinkClassifier, |
| 277 | "downlinkAction": downlinkAction}) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 278 | // Ignore private VLAN flow given by decomposer, cannot do anything with this flow |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 279 | if uint32(downlinkClassifier[METADATA].(uint64)) == MkUniPortNum(intfId, onuId, uniId) && |
| 280 | downlinkClassifier[VLAN_VID] == (uint32(ofp.OfpVlanId_OFPVID_PRESENT)|4000) { |
| 281 | log.Infow("EAPOL DL flow , Already added ,ignoring it", log.Fields{"downlinkClassifier": downlinkClassifier, |
| 282 | "downlinkAction": downlinkAction}) |
| 283 | return |
| 284 | } |
| 285 | /* Already this info available classifier? */ |
| 286 | downlinkAction[POP_VLAN] = true |
| 287 | downlinkAction[VLAN_VID] = downlinkClassifier[VLAN_VID] |
| 288 | f.addHSIAFlow(intfId, onuId, uniId, portNo, downlinkClassifier, downlinkAction, |
| 289 | DOWNSTREAM, logicalFlow, allocId, gemportId) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 290 | } |
| 291 | |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 292 | func (f *OpenOltFlowMgr) addHSIAFlow(intfId uint32, onuId uint32, uniId uint32, portNo uint32, classifier map[string]interface{}, |
| 293 | action map[string]interface{}, direction string, logicalFlow *ofp.OfpFlowStats, |
| 294 | allocId uint32, gemPortId uint32) { |
| 295 | /* One of the OLT platform (Broadcom BAL) requires that symmetric |
| 296 | flows require the same flow_id to be used across UL and DL. |
| 297 | Since HSIA flow is the only symmetric flow currently, we need to |
| 298 | re-use the flow_id across both direction. The 'flow_category' |
| 299 | takes priority over flow_cookie to find any available HSIA_FLOW |
| 300 | id for the ONU. |
| 301 | */ |
| 302 | log.Debugw("Adding HSIA flow", log.Fields{"intfId": intfId, "onuId": onuId, "uniId": uniId, "classifier": classifier, |
| 303 | "action": action, "direction": direction, "allocId": allocId, "gemPortId": gemPortId, |
| 304 | "logicalFlow": *logicalFlow}) |
| 305 | flowStoreCookie := getFlowStoreCookie(classifier, gemPortId) |
| 306 | flowId, err := f.resourceMgr.GetFlowID(intfId, onuId, uniId, flowStoreCookie, "HSIA") |
| 307 | if err != nil { |
| 308 | log.Errorw("Flow id unavailable for HSIA flow", log.Fields{"direction": direction}) |
| 309 | return |
| 310 | } |
| 311 | var classifierProto *openolt_pb2.Classifier |
| 312 | var actionProto *openolt_pb2.Action |
| 313 | if classifierProto = makeOpenOltClassifierField(classifier); classifierProto == nil { |
| 314 | log.Error("Error in making classifier protobuf for hsia flow") |
| 315 | return |
| 316 | } |
| 317 | log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto}) |
| 318 | if actionProto = makeOpenOltActionField(action); actionProto == nil { |
| 319 | log.Errorw("Error in making action protobuf for hsia flow", log.Fields{"direction": direction}) |
| 320 | return |
| 321 | } |
| 322 | log.Debugw("Created action proto", log.Fields{"action": *actionProto}) |
| 323 | flow := openolt_pb2.Flow{AccessIntfId: int32(intfId), |
| 324 | OnuId: int32(onuId), |
| 325 | UniId: int32(uniId), |
| 326 | FlowId: flowId, |
| 327 | FlowType: direction, |
| 328 | AllocId: int32(allocId), |
| 329 | NetworkIntfId: DEFAULT_NETWORK_INTERFACE_ID, // one NNI port is supported now |
| 330 | GemportId: int32(gemPortId), |
| 331 | Classifier: classifierProto, |
| 332 | Action: actionProto, |
| 333 | Priority: int32(logicalFlow.Priority), |
| 334 | Cookie: logicalFlow.Cookie, |
| 335 | PortNo: portNo} |
| 336 | if ok := f.addFlowToDevice(&flow); ok { |
| 337 | log.Debug("HSIA flow added to device successfully", log.Fields{"direction": direction}) |
| 338 | flowsToKVStore := f.getUpdatedFlowInfo(&flow, flowStoreCookie, "HSIA") |
| 339 | if err := f.updateFlowInfoToKVStore(flow.AccessIntfId, |
| 340 | flow.OnuId, |
| 341 | flow.UniId, |
| 342 | flow.FlowId, flowsToKVStore); err != nil { |
| 343 | log.Errorw("Error uploading HSIA flow into KV store", log.Fields{"flow": flow, "direction": direction, "error": err}) |
| 344 | return |
| 345 | } |
| 346 | } |
| 347 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 348 | 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] | 349 | |
| 350 | var dhcpFlow openolt_pb2.Flow |
| 351 | var actionProto *openolt_pb2.Action |
| 352 | var classifierProto *openolt_pb2.Classifier |
| 353 | |
| 354 | // Clear the action map |
| 355 | for k := range action { |
| 356 | delete(action, k) |
| 357 | } |
| 358 | |
| 359 | action[TRAP_TO_HOST] = true |
| 360 | classifier[UDP_SRC] = 68 |
| 361 | classifier[UDP_DST] = 67 |
| 362 | classifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 363 | delete(classifier, VLAN_VID) |
| 364 | |
| 365 | flowStoreCookie := getFlowStoreCookie(classifier, gemPortId) |
| 366 | |
| 367 | flowID, err := f.resourceMgr.GetFlowID(intfId, onuId, uniId, flowStoreCookie, "") |
| 368 | |
| 369 | if err != nil { |
| 370 | log.Errorw("flowId unavailable for UL EAPOL", log.Fields{"intfId": intfId, "onuId": onuId, "flowStoreCookie": flowStoreCookie}) |
| 371 | return |
| 372 | } |
| 373 | |
| 374 | log.Debugw("Creating UL DHCP flow", log.Fields{"ul_classifier": classifier, "ul_action": action, "uplinkFlowId": flowID}) |
| 375 | |
| 376 | if classifierProto = makeOpenOltClassifierField(classifier); classifierProto == nil { |
| 377 | log.Error("Error in making classifier protobuf for ul flow") |
| 378 | return |
| 379 | } |
| 380 | log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto}) |
| 381 | if actionProto = makeOpenOltActionField(action); actionProto == nil { |
| 382 | log.Error("Error in making action protobuf for ul flow") |
| 383 | return |
| 384 | } |
| 385 | |
| 386 | dhcpFlow = openolt_pb2.Flow{AccessIntfId: int32(intfId), |
| 387 | OnuId: int32(onuId), |
| 388 | UniId: int32(uniId), |
| 389 | FlowId: flowID, |
| 390 | FlowType: UPSTREAM, |
| 391 | AllocId: int32(allocId), |
| 392 | NetworkIntfId: DEFAULT_NETWORK_INTERFACE_ID, // one NNI port is supported now |
| 393 | GemportId: int32(gemPortId), |
| 394 | Classifier: classifierProto, |
| 395 | Action: actionProto, |
| 396 | Priority: int32(logicalFlow.Priority), |
| 397 | Cookie: logicalFlow.Cookie, |
| 398 | PortNo: portNo} |
| 399 | |
| 400 | if ok := f.addFlowToDevice(&dhcpFlow); ok { |
| 401 | log.Debug("DHCP UL flow added to device successfully") |
| 402 | flowsToKVStore := f.getUpdatedFlowInfo(&dhcpFlow, flowStoreCookie, "DHCP") |
| 403 | if err := f.updateFlowInfoToKVStore(dhcpFlow.AccessIntfId, |
| 404 | dhcpFlow.OnuId, |
| 405 | dhcpFlow.UniId, |
| 406 | dhcpFlow.FlowId, flowsToKVStore); err != nil { |
| 407 | log.Errorw("Error uploading DHCP UL flow into KV store", log.Fields{"flow": dhcpFlow, "error": err}) |
| 408 | return |
| 409 | } |
| 410 | } |
| 411 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 412 | return |
| 413 | } |
| 414 | |
| 415 | // Add EAPOL to device |
| 416 | func (f *OpenOltFlowMgr) addEAPOLFlow(intfId uint32, onuId uint32, uniId uint32, portNo uint32, logicalFlow *ofp.OfpFlowStats, allocId uint32, gemPortId uint32, vlanId uint32) { |
| 417 | log.Debugw("Adding EAPOL to device", log.Fields{"intfId": intfId, "onuId": onuId, "portNo": portNo, "allocId": allocId, "gemPortId": gemPortId, "vlanId": vlanId, "flow": logicalFlow}) |
| 418 | |
| 419 | uplinkClassifier := make(map[string]interface{}) |
| 420 | uplinkAction := make(map[string]interface{}) |
| 421 | downlinkClassifier := make(map[string]interface{}) |
| 422 | downlinkAction := make(map[string]interface{}) |
| 423 | var upstreamFlow openolt_pb2.Flow |
| 424 | var downstreamFlow openolt_pb2.Flow |
| 425 | |
| 426 | // Fill Classfier |
| 427 | uplinkClassifier[ETH_TYPE] = uint32(EAP_ETH_TYPE) |
| 428 | uplinkClassifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 429 | uplinkClassifier[VLAN_VID] = vlanId |
| 430 | // Fill action |
| 431 | uplinkAction[TRAP_TO_HOST] = true |
| 432 | flowStoreCookie := getFlowStoreCookie(uplinkClassifier, gemPortId) |
| 433 | //Add Uplink EAPOL Flow |
| 434 | uplinkFlowId, err := f.resourceMgr.GetFlowID(intfId, onuId, uniId, flowStoreCookie, "") |
| 435 | if err != nil { |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 436 | log.Errorw("flowId unavailable for UL EAPOL", log.Fields{"intfId": intfId, "onuId": onuId, "flowStoreCookie": flowStoreCookie}) |
| 437 | return |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 438 | } |
| 439 | var classifierProto *openolt_pb2.Classifier |
| 440 | var actionProto *openolt_pb2.Action |
| 441 | log.Debugw("Creating UL EAPOL flow", log.Fields{"ul_classifier": uplinkClassifier, "ul_action": uplinkAction, "uplinkFlowId": uplinkFlowId}) |
| 442 | |
| 443 | if classifierProto = makeOpenOltClassifierField(uplinkClassifier); classifierProto == nil { |
| 444 | log.Error("Error in making classifier protobuf for ul flow") |
| 445 | return |
| 446 | } |
| 447 | log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto}) |
| 448 | if actionProto = makeOpenOltActionField(uplinkAction); actionProto == nil { |
| 449 | log.Error("Error in making action protobuf for ul flow") |
| 450 | return |
| 451 | } |
| 452 | log.Debugw("Created action proto", log.Fields{"action": *actionProto}) |
| 453 | upstreamFlow = openolt_pb2.Flow{AccessIntfId: int32(intfId), |
| 454 | OnuId: int32(onuId), |
| 455 | UniId: int32(uniId), |
| 456 | FlowId: uplinkFlowId, |
| 457 | FlowType: UPSTREAM, |
| 458 | AllocId: int32(allocId), |
| 459 | NetworkIntfId: DEFAULT_NETWORK_INTERFACE_ID, // one NNI port is supported now |
| 460 | GemportId: int32(gemPortId), |
| 461 | Classifier: classifierProto, |
| 462 | Action: actionProto, |
| 463 | Priority: int32(logicalFlow.Priority), |
| 464 | Cookie: logicalFlow.Cookie, |
| 465 | PortNo: portNo} |
| 466 | if ok := f.addFlowToDevice(&upstreamFlow); ok { |
| 467 | log.Debug("EAPOL UL flow added to device successfully") |
| 468 | flowsToKVStore := f.getUpdatedFlowInfo(&upstreamFlow, flowStoreCookie, "EAPOL") |
| 469 | if err := f.updateFlowInfoToKVStore(upstreamFlow.AccessIntfId, |
| 470 | upstreamFlow.OnuId, |
| 471 | upstreamFlow.UniId, |
| 472 | upstreamFlow.FlowId, flowsToKVStore); err != nil { |
| 473 | log.Errorw("Error uploading EAPOL UL flow into KV store", log.Fields{"flow": upstreamFlow, "error": err}) |
| 474 | return |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | if vlanId == DEFAULT_MGMT_VLAN { |
| 479 | /* Add Downstream EAPOL Flow, Only for first EAP flow (BAL |
| 480 | # requirement) |
| 481 | # On one of the platforms (Broadcom BAL), when same DL classifier |
| 482 | # vlan was used across multiple ONUs, eapol flow re-adds after |
| 483 | # flow delete (cases of onu reboot/disable) fails. |
| 484 | # In order to generate unique vlan, a combination of intf_id |
| 485 | # onu_id and uniId is used. |
| 486 | # uniId defaults to 0, so add 1 to it. |
| 487 | */ |
| 488 | log.Debugw("Creating DL EAPOL flow with default vlan", log.Fields{"vlan": vlanId}) |
| 489 | specialVlanDlFlow := 4090 - intfId*onuId*(uniId+1) |
| 490 | // Assert that we do not generate invalid vlans under no condition |
| 491 | if specialVlanDlFlow <= 2 { |
| 492 | log.Fatalw("invalid-vlan-generated", log.Fields{"vlan": specialVlanDlFlow}) |
| 493 | return |
| 494 | } |
| 495 | log.Debugw("specialVlanEAPOLDlFlow:", log.Fields{"dl_vlan": specialVlanDlFlow}) |
| 496 | // Fill Classfier |
| 497 | downlinkClassifier[PACKET_TAG_TYPE] = SINGLE_TAG |
| 498 | downlinkClassifier[VLAN_VID] = uint32(specialVlanDlFlow) |
| 499 | // Fill action |
| 500 | downlinkAction[PUSH_VLAN] = true |
| 501 | downlinkAction[VLAN_VID] = vlanId |
| 502 | flowStoreCookie := getFlowStoreCookie(downlinkClassifier, gemPortId) |
| 503 | downlinkFlowId, err := f.resourceMgr.GetFlowID(intfId, onuId, uniId, flowStoreCookie, "") |
| 504 | if err != nil { |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 505 | log.Errorw("flowId unavailable for DL EAPOL", |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 506 | log.Fields{"intfId": intfId, "onuId": onuId, "flowStoreCookie": flowStoreCookie}) |
| 507 | return |
| 508 | } |
| 509 | log.Debugw("Creating DL EAPOL flow", |
| 510 | log.Fields{"dl_classifier": downlinkClassifier, "dl_action": downlinkAction, "downlinkFlowId": downlinkFlowId}) |
| 511 | if classifierProto = makeOpenOltClassifierField(downlinkClassifier); classifierProto == nil { |
| 512 | log.Error("Error in making classifier protobuf for downlink flow") |
| 513 | return |
| 514 | } |
| 515 | if actionProto = makeOpenOltActionField(downlinkAction); actionProto == nil { |
| 516 | log.Error("Error in making action protobuf for dl flow") |
| 517 | return |
| 518 | } |
| 519 | // Downstream flow in grpc protobuf |
| 520 | downstreamFlow = openolt_pb2.Flow{AccessIntfId: int32(intfId), |
| 521 | OnuId: int32(onuId), |
| 522 | UniId: int32(uniId), |
| 523 | FlowId: downlinkFlowId, |
| 524 | FlowType: DOWNSTREAM, |
| 525 | AllocId: int32(allocId), |
| 526 | NetworkIntfId: DEFAULT_NETWORK_INTERFACE_ID, |
| 527 | GemportId: int32(gemPortId), |
| 528 | Classifier: classifierProto, |
| 529 | Action: actionProto, |
| 530 | Priority: int32(logicalFlow.Priority), |
| 531 | Cookie: logicalFlow.Cookie, |
| 532 | PortNo: portNo} |
| 533 | if ok := f.addFlowToDevice(&downstreamFlow); ok { |
| 534 | log.Debug("EAPOL DL flow added to device successfully") |
| 535 | flowsToKVStore := f.getUpdatedFlowInfo(&downstreamFlow, flowStoreCookie, "") |
| 536 | if err := f.updateFlowInfoToKVStore(downstreamFlow.AccessIntfId, |
| 537 | downstreamFlow.OnuId, |
| 538 | downstreamFlow.UniId, |
| 539 | downstreamFlow.FlowId, flowsToKVStore); err != nil { |
| 540 | log.Errorw("Error uploading EAPOL DL flow into KV store", log.Fields{"flow": upstreamFlow, "error": err}) |
| 541 | return |
| 542 | } |
| 543 | } |
| 544 | } else { |
| 545 | log.Infow("EAPOL flow with non-default mgmt vlan is not supported", log.Fields{"vlanId": vlanId}) |
| 546 | return |
| 547 | } |
| 548 | log.Debugw("Added EAPOL flows to device successfully", log.Fields{"flow": logicalFlow}) |
| 549 | } |
| 550 | |
| 551 | func makeOpenOltClassifierField(classifierInfo map[string]interface{}) *openolt_pb2.Classifier { |
| 552 | var classifier openolt_pb2.Classifier |
| 553 | if etherType, ok := classifierInfo[ETH_TYPE]; ok { |
| 554 | classifier.EthType = etherType.(uint32) |
| 555 | } |
| 556 | if ipProto, ok := classifierInfo[IP_PROTO]; ok { |
| 557 | classifier.IpProto = ipProto.(uint32) |
| 558 | } |
| 559 | if vlanId, ok := classifierInfo[VLAN_VID]; ok { |
| 560 | classifier.OVid = vlanId.(uint32) |
| 561 | } |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 562 | if metadata, ok := classifierInfo[METADATA]; ok { // TODO: Revisit |
| 563 | classifier.IVid = uint32(metadata.(uint64)) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 564 | } |
| 565 | if vlanPcp, ok := classifierInfo[VLAN_PCP]; ok { |
| 566 | classifier.OPbits = vlanPcp.(uint32) |
| 567 | } |
| 568 | if udpSrc, ok := classifierInfo[UDP_SRC]; ok { |
| 569 | classifier.SrcPort = udpSrc.(uint32) |
| 570 | } |
| 571 | if udpDst, ok := classifierInfo[UDP_DST]; ok { |
| 572 | classifier.DstPort = udpDst.(uint32) |
| 573 | } |
| 574 | if ipv4Dst, ok := classifierInfo[IPV4_DST]; ok { |
| 575 | classifier.DstIp = ipv4Dst.(uint32) |
| 576 | } |
| 577 | if ipv4Src, ok := classifierInfo[IPV4_SRC]; ok { |
| 578 | classifier.SrcIp = ipv4Src.(uint32) |
| 579 | } |
| 580 | if pktTagType, ok := classifierInfo[PACKET_TAG_TYPE]; ok { |
| 581 | if pktTagType.(string) == SINGLE_TAG { |
| 582 | classifier.PktTagType = SINGLE_TAG |
| 583 | } else if pktTagType.(string) == DOUBLE_TAG { |
| 584 | classifier.PktTagType = DOUBLE_TAG |
| 585 | } else if pktTagType.(string) == UNTAGGED { |
| 586 | classifier.PktTagType = UNTAGGED |
| 587 | } else { |
| 588 | log.Error("Invalid tag type in classifier") // should not hit |
| 589 | return nil |
| 590 | } |
| 591 | } |
| 592 | return &classifier |
| 593 | } |
| 594 | |
| 595 | func makeOpenOltActionField(actionInfo map[string]interface{}) *openolt_pb2.Action { |
| 596 | var actionCmd openolt_pb2.ActionCmd |
| 597 | var action openolt_pb2.Action |
| 598 | action.Cmd = &actionCmd |
| 599 | if _, ok := actionInfo[POP_VLAN]; ok { |
| 600 | action.OVid = actionInfo[VLAN_VID].(uint32) |
| 601 | action.Cmd.RemoveOuterTag = true |
| 602 | } else if _, ok := actionInfo[PUSH_VLAN]; ok { |
| 603 | action.OVid = actionInfo[VLAN_VID].(uint32) |
| 604 | action.Cmd.AddOuterTag = true |
| 605 | } else if _, ok := actionInfo[TRAP_TO_HOST]; ok { |
| 606 | action.Cmd.TrapToHost = actionInfo[TRAP_TO_HOST].(bool) |
| 607 | } else { |
| 608 | log.Errorw("Invalid-action-field", log.Fields{"action": actionInfo}) |
| 609 | return nil |
| 610 | } |
| 611 | return &action |
| 612 | } |
| 613 | |
| 614 | func (f *OpenOltFlowMgr) getTPpath(intfId uint32, uni string) string { |
| 615 | /* |
| 616 | FIXME |
| 617 | Should get Table id form the flow, as of now hardcoded to DEFAULT_TECH_PROFILE_TABLE_ID (64) |
| 618 | 'tp_path' contains the suffix part of the tech_profile_instance path. The prefix to the 'tp_path' should be set to |
| 619 | TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX by the ONU adapter. |
| 620 | */ |
| 621 | return f.techprofile[intfId].GetTechProfileInstanceKVPath(tp.DEFAULT_TECH_PROFILE_TABLE_ID, uni) |
| 622 | } |
| 623 | |
| 624 | func getFlowStoreCookie(classifier map[string]interface{}, gemPortId uint32) uint64 { |
| 625 | if len(classifier) == 0 { // should never happen |
| 626 | log.Error("Invalid classfier object") |
| 627 | return 0 |
| 628 | } |
| 629 | var jsonData []byte |
| 630 | var flowString string |
| 631 | var err error |
| 632 | // TODO: Do we need to marshall ?? |
| 633 | if jsonData, err = json.Marshal(classifier); err != nil { |
| 634 | log.Error("Failed to encode classifier") |
| 635 | return 0 |
| 636 | } |
| 637 | flowString = string(jsonData) |
| 638 | if gemPortId != 0 { |
| 639 | flowString = fmt.Sprintf("%s%s", string(jsonData), string(gemPortId)) |
| 640 | } |
| 641 | h := md5.New() |
| 642 | h.Write([]byte(flowString)) |
| 643 | hash := big.NewInt(0) |
| 644 | hash.SetBytes(h.Sum(nil)) |
| 645 | return hash.Uint64() |
| 646 | } |
| 647 | |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 648 | func (f *OpenOltFlowMgr) getUpdatedFlowInfo(flow *openolt_pb2.Flow, flowStoreCookie uint64, flowCategory string) *[]rsrcMgr.FlowInfo { |
| 649 | var flows []rsrcMgr.FlowInfo = []rsrcMgr.FlowInfo{rsrcMgr.FlowInfo{Flow: flow, FlowCategory: flowCategory, FlowStoreCookie: flowStoreCookie}} |
| 650 | // Get existing flow for flowid for given subscriber from KV store |
| 651 | existingFlows := f.resourceMgr.GetFlowIDInfo(uint32(flow.AccessIntfId), uint32(flow.OnuId), uint32(flow.UniId), flow.FlowId) |
| 652 | if existingFlows != nil { |
| 653 | log.Debugw("Flow exists for given flowID, appending it to current flow", log.Fields{"flowID": flow.FlowId}) |
| 654 | for _, f := range *existingFlows { |
| 655 | flows = append(flows, f) |
| 656 | } |
| 657 | } |
| 658 | 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] | 659 | return &flows |
| 660 | } |
| 661 | |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 662 | func (f *OpenOltFlowMgr) updateFlowInfoToKVStore(intfId int32, onuId int32, uniId int32, flowId uint32, flows *[]rsrcMgr.FlowInfo) error { |
| 663 | log.Debugw("Storing flow(s) into KV store", log.Fields{"flows": *flows}) |
| 664 | if err := f.resourceMgr.UpdateFlowIDInfo(intfId, onuId, uniId, flowId, flows); err != nil { |
| 665 | log.Debug("Error while Storing flow into KV store") |
| 666 | return err |
| 667 | } |
| 668 | log.Info("Stored flow(s) into KV store successfully!") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 669 | return nil |
| 670 | } |
| 671 | |
| 672 | func (f *OpenOltFlowMgr) addFlowToDevice(deviceFlow *openolt_pb2.Flow) bool { |
| 673 | log.Debugw("Sending flow to device via grpc", log.Fields{"flow": *deviceFlow}) |
| 674 | _, err := f.deviceHandler.Client.FlowAdd(context.Background(), deviceFlow) |
| 675 | if err != nil { |
| 676 | log.Errorw("Failed to Add flow to device", log.Fields{"err": err, "deviceFlow": deviceFlow}) |
| 677 | return false |
| 678 | } |
| 679 | log.Debugw("Flow added to device successfuly ", log.Fields{"flow": *deviceFlow}) |
| 680 | return true |
| 681 | } |
| 682 | |
| 683 | /*func register_flow(deviceFlow *openolt_pb2.Flow, logicalFlow *ofp.OfpFlowStats){ |
| 684 | //update core flows_proxy : flows_proxy.update('/', flows) |
| 685 | } |
| 686 | |
| 687 | func generateStoredId(flowId uint32, direction string)uint32{ |
| 688 | |
| 689 | if direction == UPSTREAM{ |
| 690 | log.Debug("Upstream flow shifting flowid") |
| 691 | return ((0x1 << 15) | flowId) |
| 692 | }else if direction == DOWNSTREAM{ |
| 693 | log.Debug("Downstream flow not shifting flowid") |
| 694 | return flowId |
| 695 | }else{ |
| 696 | log.Errorw("Unrecognized direction",log.Fields{"direction": direction}) |
| 697 | return flowId |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | */ |
| 702 | |
| 703 | func addLLDPFlow(flow *ofp.OfpFlowStats, portNo uint32) { |
| 704 | log.Info("Unimplemented") |
| 705 | } |
| 706 | func getUniPortPath(intfId uint32, onuId uint32, uniId uint32) string { |
| 707 | return fmt.Sprintf("pon-{%d}/onu-{%d}/uni-{%d}", intfId, onuId, uniId) |
| 708 | } |
| 709 | |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 710 | func (f *OpenOltFlowMgr) getOnuChildDevice(intfId uint32, onuId uint32) (*voltha.Device, error) { |
| 711 | log.Debugw("GetChildDevice", log.Fields{"pon port": intfId, "onuId": onuId}) |
| 712 | //parentPortNo := IntfIdToPortNo(intfId, voltha.Port_PON_OLT) |
| 713 | parentPortNo := intfId |
| 714 | onuDevice := f.deviceHandler.GetChildDevice(parentPortNo, onuId) |
| 715 | if onuDevice == nil { |
| 716 | log.Errorw("onu not found", log.Fields{"intfId": parentPortNo, "onuId": onuId}) |
| 717 | return nil, errors.New("onu not found") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 718 | } |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 719 | log.Debugw("Successfully received child device from core", log.Fields{"child_device": *onuDevice}) |
| 720 | return onuDevice, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | func findNextFlow(flow *ofp.OfpFlowStats) *ofp.OfpFlowStats { |
| 724 | log.Info("Unimplemented") |
| 725 | return nil |
| 726 | } |
| 727 | |
| 728 | func getSubscriberVlan(inPort uint32) uint32 { |
| 729 | /* For EAPOL case we will use default VLAN , so will implement later if required */ |
| 730 | log.Info("Unimplemented") |
| 731 | return 0 |
| 732 | } |
| 733 | |
| 734 | func (f *OpenOltFlowMgr) clear_flows_and_scheduler_for_logical_port(childDevice *voltha.Device, logicalPort *voltha.LogicalPort) { |
| 735 | log.Info("Unimplemented") |
| 736 | } |
| 737 | |
| 738 | func (f *OpenOltFlowMgr) AddFlow(flow *ofp.OfpFlowStats) { |
| 739 | classifierInfo := make(map[string]interface{}, 0) |
| 740 | actionInfo := make(map[string]interface{}, 0) |
| 741 | log.Debug("Adding Flow", log.Fields{"flow": flow}) |
| 742 | for _, field := range fd.GetOfbFields(flow) { |
| 743 | if field.Type == fd.ETH_TYPE { |
| 744 | classifierInfo[ETH_TYPE] = field.GetEthType() |
| 745 | log.Debug("field-type-eth-type", log.Fields{"classifierInfo[ETH_TYPE]": classifierInfo[ETH_TYPE].(uint32)}) |
| 746 | } else if field.Type == fd.IP_PROTO { |
| 747 | classifierInfo[IP_PROTO] = field.GetIpProto() |
| 748 | log.Debug("field-type-ip-proto", log.Fields{"classifierInfo[IP_PROTO]": classifierInfo[IP_PROTO].(uint32)}) |
| 749 | } else if field.Type == fd.IN_PORT { |
| 750 | classifierInfo[IN_PORT] = field.GetPort() |
| 751 | log.Debug("field-type-in-port", log.Fields{"classifierInfo[IN_PORT]": classifierInfo[IN_PORT].(uint32)}) |
| 752 | } else if field.Type == fd.VLAN_VID { |
| 753 | classifierInfo[VLAN_VID] = field.GetVlanVid() |
| 754 | log.Debug("field-type-vlan-vid", log.Fields{"classifierInfo[VLAN_VID]": classifierInfo[VLAN_VID].(uint32)}) |
| 755 | } else if field.Type == fd.VLAN_PCP { |
| 756 | classifierInfo[VLAN_PCP] = field.GetVlanPcp() |
| 757 | log.Debug("field-type-vlan-pcp", log.Fields{"classifierInfo[VLAN_PCP]": classifierInfo[VLAN_PCP].(uint32)}) |
| 758 | } else if field.Type == fd.UDP_DST { |
| 759 | classifierInfo[UDP_DST] = field.GetUdpDst() |
| 760 | log.Debug("field-type-udp-dst", log.Fields{"classifierInfo[UDP_DST]": classifierInfo[UDP_DST].(uint32)}) |
| 761 | } else if field.Type == fd.UDP_SRC { |
| 762 | classifierInfo[UDP_SRC] = field.GetUdpSrc() |
| 763 | log.Debug("field-type-udp-src", log.Fields{"classifierInfo[UDP_SRC]": classifierInfo[UDP_SRC].(uint32)}) |
| 764 | } else if field.Type == fd.IPV4_DST { |
| 765 | classifierInfo[IPV4_DST] = field.GetIpv4Dst() |
| 766 | log.Debug("field-type-ipv4-dst", log.Fields{"classifierInfo[IPV4_DST]": classifierInfo[IPV4_DST].(uint32)}) |
| 767 | } else if field.Type == fd.IPV4_SRC { |
| 768 | classifierInfo[IPV4_SRC] = field.GetIpv4Src() |
| 769 | log.Debug("field-type-ipv4-src", log.Fields{"classifierInfo[IPV4_SRC]": classifierInfo[IPV4_SRC].(uint32)}) |
| 770 | } else if field.Type == fd.METADATA { |
| 771 | classifierInfo[METADATA] = field.GetTableMetadata() |
| 772 | log.Debug("field-type-metadata", log.Fields{"classifierInfo[METADATA]": classifierInfo[METADATA].(uint64)}) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 773 | } else if field.Type == fd.TUNNEL_ID { |
| 774 | classifierInfo[TUNNEL_ID] = field.GetTunnelId() |
| 775 | log.Debug("field-type-tunnelId", log.Fields{"classifierInfo[TUNNEL_ID]": classifierInfo[TUNNEL_ID].(uint64)}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 776 | } else { |
| 777 | log.Errorw("Un supported field type", log.Fields{"type": field.Type}) |
| 778 | return |
| 779 | } |
| 780 | } |
| 781 | for _, action := range fd.GetActions(flow) { |
| 782 | if action.Type == fd.OUTPUT { |
| 783 | if out := action.GetOutput(); out != nil { |
| 784 | actionInfo[OUTPUT] = out.GetPort() |
| 785 | log.Debugw("action-type-output", log.Fields{"out_port": actionInfo[OUTPUT].(uint32)}) |
| 786 | } else { |
| 787 | log.Error("Invalid output port in action") |
| 788 | return |
| 789 | } |
| 790 | } else if action.Type == fd.POP_VLAN { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 791 | actionInfo[POP_VLAN] = true |
| 792 | log.Debugw("action-type-pop-vlan", log.Fields{"in_port": classifierInfo[IN_PORT].(uint32)}) |
| 793 | } else if action.Type == fd.PUSH_VLAN { |
| 794 | if out := action.GetPush(); out != nil { |
| 795 | if tpid := out.GetEthertype(); tpid != 0x8100 { |
| 796 | log.Errorw("Invalid ethertype in push action", log.Fields{"ethertype": actionInfo[PUSH_VLAN].(int32)}) |
| 797 | } else { |
| 798 | actionInfo[PUSH_VLAN] = true |
| 799 | actionInfo[TPID] = tpid |
| 800 | log.Debugw("action-type-push-vlan", |
| 801 | log.Fields{"push_tpid": actionInfo[TPID].(uint32), "in_port": classifierInfo[IN_PORT].(uint32)}) |
| 802 | } |
| 803 | } |
| 804 | } else if action.Type == fd.SET_FIELD { |
| 805 | if out := action.GetSetField(); out != nil { |
| 806 | if field := out.GetField(); field != nil { |
| 807 | if ofClass := field.GetOxmClass(); ofClass != ofp.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
| 808 | log.Errorw("Invalid openflow class", log.Fields{"class": ofClass}) |
| 809 | return |
| 810 | } |
| 811 | /*log.Debugw("action-type-set-field",log.Fields{"field": field, "in_port": classifierInfo[IN_PORT].(uint32)})*/ |
| 812 | if ofbField := field.GetOfbField(); ofbField != nil { |
| 813 | if fieldtype := ofbField.GetType(); fieldtype == ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
| 814 | if vlan := ofbField.GetVlanVid(); vlan != 0 { |
| 815 | actionInfo[VLAN_VID] = vlan & 0xfff |
| 816 | log.Debugw("action-set-vlan-vid", log.Fields{"actionInfo[VLAN_VID]": actionInfo[VLAN_VID].(uint32)}) |
| 817 | } else { |
| 818 | log.Error("No Invalid vlan id in set vlan-vid action") |
| 819 | } |
| 820 | } else { |
| 821 | log.Errorw("unsupported-action-set-field-type", log.Fields{"type": fieldtype}) |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | } else { |
| 827 | log.Errorw("Un supported action type", log.Fields{"type": action.Type}) |
| 828 | return |
| 829 | } |
| 830 | } |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 831 | /* Controller bound trap flows */ |
| 832 | if isControllerFlow := IsControllerBoundFlow(actionInfo[OUTPUT].(uint32)); isControllerFlow { |
| 833 | log.Debug("Controller bound trap flows, getting inport from tunnelid") |
| 834 | /* Get UNI port/ IN Port from tunnel ID field for upstream controller bound flows */ |
| 835 | if portType := IntfIdToPortTypeName(classifierInfo[IN_PORT].(uint32)); portType == voltha.Port_PON_OLT { |
| 836 | if uniPort := fd.GetChildPortFromTunnelId(flow); uniPort != 0 { |
| 837 | classifierInfo[IN_PORT] = uniPort |
| 838 | log.Debugw("upstream pon-to-controller-flow,inport-in-tunnelid", log.Fields{"newInPort": classifierInfo[IN_PORT].(uint32), "outPort": actionInfo[OUTPUT].(uint32)}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 839 | } else { |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 840 | log.Error("upstream pon-to-controller-flow, NO-inport-in-tunnelid") |
| 841 | return |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 842 | } |
| 843 | } |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 844 | } else { |
| 845 | log.Debug("Non-Controller flows, getting uniport from tunnelid") |
| 846 | // Downstream flow from NNI to PON port , Use tunnel ID as new OUT port / UNI port |
| 847 | if portType := IntfIdToPortTypeName(actionInfo[OUTPUT].(uint32)); portType == voltha.Port_PON_OLT { |
| 848 | if uniPort := fd.GetChildPortFromTunnelId(flow); uniPort != 0 { |
| 849 | actionInfo[OUTPUT] = uniPort |
| 850 | log.Debugw("downstream-nni-to-pon-port-flow, outport-in-tunnelid", log.Fields{"newOutPort": actionInfo[OUTPUT].(uint32), "outPort": actionInfo[OUTPUT].(uint32)}) |
| 851 | } else { |
| 852 | log.Debug("downstream-nni-to-pon-port-flow, no-outport-in-tunnelid", log.Fields{"InPort": classifierInfo[IN_PORT].(uint32), "outPort": actionInfo[OUTPUT].(uint32)}) |
| 853 | return |
| 854 | } |
| 855 | // Upstream flow from PON to NNI port , Use tunnel ID as new IN port / UNI port |
| 856 | } else if portType := IntfIdToPortTypeName(classifierInfo[IN_PORT].(uint32)); portType == voltha.Port_PON_OLT { |
| 857 | if uniPort := fd.GetChildPortFromTunnelId(flow); uniPort != 0 { |
| 858 | classifierInfo[IN_PORT] = uniPort |
| 859 | log.Debugw("upstream-pon-to-nni-port-flow, inport-in-tunnelid", log.Fields{"newInPort": actionInfo[OUTPUT].(uint32), |
| 860 | "outport": actionInfo[OUTPUT].(uint32)}) |
| 861 | } else { |
| 862 | log.Debug("upstream-pon-to-nni-port-flow, no-inport-in-tunnelid", log.Fields{"InPort": classifierInfo[IN_PORT].(uint32), |
| 863 | "outPort": actionInfo[OUTPUT].(uint32)}) |
| 864 | return |
| 865 | } |
| 866 | } |
| 867 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 868 | log.Infow("Flow ports", log.Fields{"classifierInfo_inport": classifierInfo[IN_PORT], "action_output": actionInfo[OUTPUT]}) |
| 869 | portNo, intfId, onuId, uniId := ExtractAccessFromFlow(classifierInfo[IN_PORT].(uint32), actionInfo[OUTPUT].(uint32)) |
| 870 | f.divideAndAddFlow(intfId, onuId, uniId, portNo, classifierInfo, actionInfo, flow) |
| 871 | } |
| 872 | |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 873 | func (f *OpenOltFlowMgr) sendTPDownloadMsgToChild(intfId uint32, onuId uint32, uniId uint32, uni string) error { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 874 | |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 875 | onuDevice, err := f.getOnuChildDevice(intfId, onuId) |
| 876 | if err != nil { |
| 877 | log.Errorw("Error while fetching Child device from core", log.Fields{"onuId": onuId}) |
| 878 | return err |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 879 | } |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 880 | 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] | 881 | |
| 882 | tpPath := f.getTPpath(intfId, uni) |
| 883 | tpDownloadMsg := &ic.InterAdapterTechProfileDownloadMessage{UniId: uniId, Path: tpPath} |
| 884 | log.Infow("Sending Load-tech-profile-request-to-brcm-onu-adapter", log.Fields{"msg": *tpDownloadMsg}) |
| 885 | sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(context.Background(), |
| 886 | tpDownloadMsg, |
| 887 | ic.InterAdapterMessageType_TECH_PROFILE_DOWNLOAD_REQUEST, |
| 888 | f.deviceHandler.deviceType, |
| 889 | onuDevice.Type, |
| 890 | onuDevice.Id, |
| 891 | onuDevice.ProxyAddress.DeviceId, "") |
| 892 | if sendErr != nil { |
| 893 | log.Errorw("send techprofile-download request error", log.Fields{"fromAdapter": f.deviceHandler.deviceType, |
| 894 | "toAdapter": onuDevice.Type, "onuId": onuDevice.Id, |
| 895 | "proxyDeviceId": onuDevice.ProxyAddress.DeviceId}) |
| 896 | return sendErr |
| 897 | } |
| 898 | 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] | 899 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 900 | } |