Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 1 | /* |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 2 | Copyright 2020 the original author or authors. |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 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 | package openflow |
| 17 | |
| 18 | import ( |
| 19 | "encoding/json" |
| 20 | ofp "github.com/donNewtonAlpha/goloxi/of13" |
David K. Bainbridge | aea73cd | 2020-01-27 10:44:50 -0800 | [diff] [blame] | 21 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 22 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 23 | "golang.org/x/net/context" |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 24 | ) |
| 25 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame^] | 26 | func (ofc *OFConnection) handleMeterModRequest(request *ofp.MeterMod) { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 27 | if logger.V(log.DebugLevel) { |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame] | 28 | js, _ := json.Marshal(request) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 29 | logger.Debugw("handleMeterModRequest called", |
| 30 | log.Fields{ |
| 31 | "device-id": ofc.DeviceID, |
| 32 | "request": js}) |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame] | 33 | } |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 34 | |
David K. Bainbridge | 9cb404e | 2020-01-28 14:32:29 -0800 | [diff] [blame] | 35 | if ofc.VolthaClient == nil { |
| 36 | logger.Errorw("no-voltha-connection", |
| 37 | log.Fields{"device-id": ofc.DeviceID}) |
| 38 | return |
| 39 | } |
| 40 | |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 41 | meterModUpdate := openflow_13.MeterModUpdate{Id: ofc.DeviceID} |
| 42 | meterMod := openflow_13.OfpMeterMod{ |
| 43 | MeterId: request.MeterId, |
| 44 | Flags: uint32(request.Flags), |
| 45 | Command: openflow_13.OfpMeterModCommand(request.Command), |
| 46 | } |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 47 | var bands []*openflow_13.OfpMeterBandHeader |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 48 | for _, ofpBand := range request.GetMeters() { |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 49 | var band openflow_13.OfpMeterBandHeader |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 50 | switch ofpBand.GetType() { |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 51 | case ofp.OFPMBTDrop: |
| 52 | ofpDrop := ofpBand.(ofp.IMeterBandDrop) |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 53 | band.Type = openflow_13.OfpMeterBandType_OFPMBT_DROP |
| 54 | band.Rate = ofpDrop.GetRate() |
Don Newton | b437c6f | 2019-12-18 11:51:57 -0500 | [diff] [blame] | 55 | band.BurstSize = ofpDrop.GetBurstSize() |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 56 | case ofp.OFPMBTDSCPRemark: |
| 57 | ofpDscpRemark := ofpBand.(ofp.IMeterBandDscpRemark) |
| 58 | var dscpRemark openflow_13.OfpMeterBandDscpRemark |
| 59 | band.Type = openflow_13.OfpMeterBandType_OFPMBT_DSCP_REMARK |
| 60 | band.BurstSize = ofpDscpRemark.GetBurstSize() |
| 61 | band.Rate = ofpDscpRemark.GetRate() |
| 62 | dscpRemark.PrecLevel = uint32(ofpDscpRemark.GetPrecLevel()) |
Don Newton | b437c6f | 2019-12-18 11:51:57 -0500 | [diff] [blame] | 63 | /* |
| 64 | var meterBandHeaderDscp openflow_13.OfpMeterBandHeader_DscpRemark |
| 65 | meterBandHeaderDscp.DscpRemark = &dscpRemark |
| 66 | band.Data = &meterBandHeaderDscp |
| 67 | |
| 68 | */ |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 69 | case ofp.OFPMBTExperimenter: |
| 70 | ofpExperimenter := ofpBand.(ofp.IMeterBandExperimenter) |
| 71 | var experimenter openflow_13.OfpMeterBandExperimenter |
| 72 | experimenter.Experimenter = ofpExperimenter.GetExperimenter() |
| 73 | band.Type = openflow_13.OfpMeterBandType_OFPMBT_EXPERIMENTER |
| 74 | band.BurstSize = ofpExperimenter.GetBurstSize() |
| 75 | band.Rate = ofpExperimenter.GetRate() |
Don Newton | b437c6f | 2019-12-18 11:51:57 -0500 | [diff] [blame] | 76 | /* |
| 77 | var meterBandHeaderExperimenter openflow_13.OfpMeterBandHeader_Experimenter |
| 78 | meterBandHeaderExperimenter.Experimenter = &experimenter |
| 79 | band.Data = &meterBandHeaderExperimenter |
| 80 | |
| 81 | */ |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 82 | } |
| 83 | bands = append(bands, &band) |
| 84 | } |
| 85 | meterMod.Bands = bands |
| 86 | meterModUpdate.MeterMod = &meterMod |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 87 | if logger.V(log.DebugLevel) { |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame] | 88 | meterModJS, _ := json.Marshal(meterModUpdate) |
| 89 | logger.Debugw("handleMeterModUpdate sending request", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 90 | log.Fields{ |
| 91 | "device-id": ofc.DeviceID, |
| 92 | "meter-mod-request": meterModJS}) |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 93 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 94 | if _, err := ofc.VolthaClient.UpdateLogicalDeviceMeterTable(context.Background(), &meterModUpdate); err != nil { |
| 95 | logger.Errorw("Error calling UpdateLogicalDeviceMeterTable", |
| 96 | log.Fields{ |
| 97 | "device-id": ofc.DeviceID, |
| 98 | "error": err}) |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame] | 99 | } |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 100 | } |