blob: d4843fa48aeea047bc87bc746e8d48f97d8cb719 [file] [log] [blame]
Don Newtone0d34a82019-11-14 10:58:06 -05001/*
David K. Bainbridge157bdab2020-01-16 14:38:05 -08002Copyright 2020 the original author or authors.
Don Newtone0d34a82019-11-14 10:58:06 -05003
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*/
16package openflow
17
18import (
19 "encoding/json"
20 ofp "github.com/donNewtonAlpha/goloxi/of13"
David K. Bainbridge157bdab2020-01-16 14:38:05 -080021 "github.com/opencord/voltha-lib-go/v2/pkg/log"
Don Newtonb437c6f2019-12-18 11:51:57 -050022 "github.com/opencord/voltha-protos/v2/go/openflow_13"
Don Newtone0d34a82019-11-14 10:58:06 -050023 "golang.org/x/net/context"
Don Newtone0d34a82019-11-14 10:58:06 -050024)
25
David K. Bainbridge157bdab2020-01-16 14:38:05 -080026func (ofc *OFClient) handleMeterModRequest(request *ofp.MeterMod) {
27 if logger.V(log.DebugLevel) {
Don Newton7577f072020-01-06 12:41:11 -050028 js, _ := json.Marshal(request)
David K. Bainbridge157bdab2020-01-16 14:38:05 -080029 logger.Debugw("handleMeterModRequest called",
30 log.Fields{
31 "device-id": ofc.DeviceID,
32 "request": js})
Don Newton7577f072020-01-06 12:41:11 -050033 }
Don Newtone0d34a82019-11-14 10:58:06 -050034
David K. Bainbridge157bdab2020-01-16 14:38:05 -080035 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 Newtone0d34a82019-11-14 10:58:06 -050041 var bands []*openflow_13.OfpMeterBandHeader
David K. Bainbridge157bdab2020-01-16 14:38:05 -080042 for _, ofpBand := range request.GetMeters() {
Don Newtone0d34a82019-11-14 10:58:06 -050043 var band openflow_13.OfpMeterBandHeader
David K. Bainbridge157bdab2020-01-16 14:38:05 -080044 switch ofpBand.GetType() {
Don Newtone0d34a82019-11-14 10:58:06 -050045 case ofp.OFPMBTDrop:
46 ofpDrop := ofpBand.(ofp.IMeterBandDrop)
Don Newtone0d34a82019-11-14 10:58:06 -050047 band.Type = openflow_13.OfpMeterBandType_OFPMBT_DROP
48 band.Rate = ofpDrop.GetRate()
Don Newtonb437c6f2019-12-18 11:51:57 -050049 band.BurstSize = ofpDrop.GetBurstSize()
Don Newtone0d34a82019-11-14 10:58:06 -050050 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 Newtonb437c6f2019-12-18 11:51:57 -050057 /*
58 var meterBandHeaderDscp openflow_13.OfpMeterBandHeader_DscpRemark
59 meterBandHeaderDscp.DscpRemark = &dscpRemark
60 band.Data = &meterBandHeaderDscp
61
62 */
Don Newtone0d34a82019-11-14 10:58:06 -050063 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 Newtonb437c6f2019-12-18 11:51:57 -050070 /*
71 var meterBandHeaderExperimenter openflow_13.OfpMeterBandHeader_Experimenter
72 meterBandHeaderExperimenter.Experimenter = &experimenter
73 band.Data = &meterBandHeaderExperimenter
74
75 */
Don Newtone0d34a82019-11-14 10:58:06 -050076 }
77 bands = append(bands, &band)
78 }
79 meterMod.Bands = bands
80 meterModUpdate.MeterMod = &meterMod
David K. Bainbridge157bdab2020-01-16 14:38:05 -080081 if logger.V(log.DebugLevel) {
Don Newton7577f072020-01-06 12:41:11 -050082 meterModJS, _ := json.Marshal(meterModUpdate)
83 logger.Debugw("handleMeterModUpdate sending request",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080084 log.Fields{
85 "device-id": ofc.DeviceID,
86 "meter-mod-request": meterModJS})
Don Newtone0d34a82019-11-14 10:58:06 -050087 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -080088 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 Newton7577f072020-01-06 12:41:11 -050093 }
Don Newtone0d34a82019-11-14 10:58:06 -050094}