blob: c8ee22cfb7d2d37b1735afaacf459f7683ac414e [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. Bainbridgeaea73cd2020-01-27 10:44:50 -080021 "github.com/opencord/voltha-lib-go/v3/pkg/log"
22 "github.com/opencord/voltha-protos/v3/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
Jonathan Hart4b110f62020-03-13 17:36:19 -070026func (ofc *OFConnection) handleMeterModRequest(request *ofp.MeterMod) {
David K. Bainbridge157bdab2020-01-16 14:38:05 -080027 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. Bainbridge9cb404e2020-01-28 14:32:29 -080035 if ofc.VolthaClient == nil {
36 logger.Errorw("no-voltha-connection",
37 log.Fields{"device-id": ofc.DeviceID})
38 return
39 }
40
David K. Bainbridge157bdab2020-01-16 14:38:05 -080041 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 Newtone0d34a82019-11-14 10:58:06 -050047 var bands []*openflow_13.OfpMeterBandHeader
David K. Bainbridge157bdab2020-01-16 14:38:05 -080048 for _, ofpBand := range request.GetMeters() {
Don Newtone0d34a82019-11-14 10:58:06 -050049 var band openflow_13.OfpMeterBandHeader
David K. Bainbridge157bdab2020-01-16 14:38:05 -080050 switch ofpBand.GetType() {
Don Newtone0d34a82019-11-14 10:58:06 -050051 case ofp.OFPMBTDrop:
52 ofpDrop := ofpBand.(ofp.IMeterBandDrop)
Don Newtone0d34a82019-11-14 10:58:06 -050053 band.Type = openflow_13.OfpMeterBandType_OFPMBT_DROP
54 band.Rate = ofpDrop.GetRate()
Don Newtonb437c6f2019-12-18 11:51:57 -050055 band.BurstSize = ofpDrop.GetBurstSize()
Don Newtone0d34a82019-11-14 10:58:06 -050056 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 Newtonb437c6f2019-12-18 11:51:57 -050063 /*
64 var meterBandHeaderDscp openflow_13.OfpMeterBandHeader_DscpRemark
65 meterBandHeaderDscp.DscpRemark = &dscpRemark
66 band.Data = &meterBandHeaderDscp
67
68 */
Don Newtone0d34a82019-11-14 10:58:06 -050069 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 Newtonb437c6f2019-12-18 11:51:57 -050076 /*
77 var meterBandHeaderExperimenter openflow_13.OfpMeterBandHeader_Experimenter
78 meterBandHeaderExperimenter.Experimenter = &experimenter
79 band.Data = &meterBandHeaderExperimenter
80
81 */
Don Newtone0d34a82019-11-14 10:58:06 -050082 }
83 bands = append(bands, &band)
84 }
85 meterMod.Bands = bands
86 meterModUpdate.MeterMod = &meterMod
David K. Bainbridge157bdab2020-01-16 14:38:05 -080087 if logger.V(log.DebugLevel) {
Don Newton7577f072020-01-06 12:41:11 -050088 meterModJS, _ := json.Marshal(meterModUpdate)
89 logger.Debugw("handleMeterModUpdate sending request",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080090 log.Fields{
91 "device-id": ofc.DeviceID,
92 "meter-mod-request": meterModJS})
Don Newtone0d34a82019-11-14 10:58:06 -050093 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -080094 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 Newton7577f072020-01-06 12:41:11 -050099 }
Don Newtone0d34a82019-11-14 10:58:06 -0500100}