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