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 | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 21 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
Don Newton | b437c6f | 2019-12-18 11:51:57 -0500 | [diff] [blame] | 22 | "github.com/opencord/voltha-protos/v2/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 | |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 26 | func (ofc *OFClient) handleMeterModRequest(request *ofp.MeterMod) { |
| 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 | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 35 | meterModUpdate := openflow_13.MeterModUpdate{Id: ofc.DeviceID} |
| 36 | meterMod := openflow_13.OfpMeterMod{ |
| 37 | MeterId: request.MeterId, |
| 38 | Flags: uint32(request.Flags), |
| 39 | Command: openflow_13.OfpMeterModCommand(request.Command), |
| 40 | } |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 41 | var bands []*openflow_13.OfpMeterBandHeader |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 42 | for _, ofpBand := range request.GetMeters() { |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 43 | var band openflow_13.OfpMeterBandHeader |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 44 | switch ofpBand.GetType() { |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 45 | case ofp.OFPMBTDrop: |
| 46 | ofpDrop := ofpBand.(ofp.IMeterBandDrop) |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 47 | band.Type = openflow_13.OfpMeterBandType_OFPMBT_DROP |
| 48 | band.Rate = ofpDrop.GetRate() |
Don Newton | b437c6f | 2019-12-18 11:51:57 -0500 | [diff] [blame] | 49 | band.BurstSize = ofpDrop.GetBurstSize() |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 50 | case ofp.OFPMBTDSCPRemark: |
| 51 | ofpDscpRemark := ofpBand.(ofp.IMeterBandDscpRemark) |
| 52 | var dscpRemark openflow_13.OfpMeterBandDscpRemark |
| 53 | band.Type = openflow_13.OfpMeterBandType_OFPMBT_DSCP_REMARK |
| 54 | band.BurstSize = ofpDscpRemark.GetBurstSize() |
| 55 | band.Rate = ofpDscpRemark.GetRate() |
| 56 | dscpRemark.PrecLevel = uint32(ofpDscpRemark.GetPrecLevel()) |
Don Newton | b437c6f | 2019-12-18 11:51:57 -0500 | [diff] [blame] | 57 | /* |
| 58 | var meterBandHeaderDscp openflow_13.OfpMeterBandHeader_DscpRemark |
| 59 | meterBandHeaderDscp.DscpRemark = &dscpRemark |
| 60 | band.Data = &meterBandHeaderDscp |
| 61 | |
| 62 | */ |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 63 | case ofp.OFPMBTExperimenter: |
| 64 | ofpExperimenter := ofpBand.(ofp.IMeterBandExperimenter) |
| 65 | var experimenter openflow_13.OfpMeterBandExperimenter |
| 66 | experimenter.Experimenter = ofpExperimenter.GetExperimenter() |
| 67 | band.Type = openflow_13.OfpMeterBandType_OFPMBT_EXPERIMENTER |
| 68 | band.BurstSize = ofpExperimenter.GetBurstSize() |
| 69 | band.Rate = ofpExperimenter.GetRate() |
Don Newton | b437c6f | 2019-12-18 11:51:57 -0500 | [diff] [blame] | 70 | /* |
| 71 | var meterBandHeaderExperimenter openflow_13.OfpMeterBandHeader_Experimenter |
| 72 | meterBandHeaderExperimenter.Experimenter = &experimenter |
| 73 | band.Data = &meterBandHeaderExperimenter |
| 74 | |
| 75 | */ |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 76 | } |
| 77 | bands = append(bands, &band) |
| 78 | } |
| 79 | meterMod.Bands = bands |
| 80 | meterModUpdate.MeterMod = &meterMod |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 81 | if logger.V(log.DebugLevel) { |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame] | 82 | meterModJS, _ := json.Marshal(meterModUpdate) |
| 83 | logger.Debugw("handleMeterModUpdate sending request", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 84 | log.Fields{ |
| 85 | "device-id": ofc.DeviceID, |
| 86 | "meter-mod-request": meterModJS}) |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 87 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 88 | if _, err := ofc.VolthaClient.UpdateLogicalDeviceMeterTable(context.Background(), &meterModUpdate); err != nil { |
| 89 | logger.Errorw("Error calling UpdateLogicalDeviceMeterTable", |
| 90 | log.Fields{ |
| 91 | "device-id": ofc.DeviceID, |
| 92 | "error": err}) |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame] | 93 | } |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 94 | } |