blob: a6411bb7eeee68814ab293897fd66922c3fd34a4 [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"
David Bainbridgef8ce7d22020-04-08 12:49:41 -070020
Jonathan Hart828908c2020-04-15 14:23:45 -070021 ofp "github.com/opencord/goloxi/of13"
David K. Bainbridgeaea73cd2020-01-27 10:44:50 -080022 "github.com/opencord/voltha-lib-go/v3/pkg/log"
23 "github.com/opencord/voltha-protos/v3/go/openflow_13"
Don Newtone0d34a82019-11-14 10:58:06 -050024 "golang.org/x/net/context"
Don Newtone0d34a82019-11-14 10:58:06 -050025)
26
Jonathan Hart4b110f62020-03-13 17:36:19 -070027func (ofc *OFConnection) handleMeterModRequest(request *ofp.MeterMod) {
David K. Bainbridge157bdab2020-01-16 14:38:05 -080028 if logger.V(log.DebugLevel) {
Don Newton7577f072020-01-06 12:41:11 -050029 js, _ := json.Marshal(request)
David K. Bainbridge157bdab2020-01-16 14:38:05 -080030 logger.Debugw("handleMeterModRequest called",
31 log.Fields{
32 "device-id": ofc.DeviceID,
33 "request": js})
Don Newton7577f072020-01-06 12:41:11 -050034 }
Don Newtone0d34a82019-11-14 10:58:06 -050035
David Bainbridgef8ce7d22020-04-08 12:49:41 -070036 volthaClient := ofc.VolthaClient.Get()
37 if volthaClient == nil {
David K. Bainbridge9cb404e2020-01-28 14:32:29 -080038 logger.Errorw("no-voltha-connection",
39 log.Fields{"device-id": ofc.DeviceID})
40 return
41 }
42
David K. Bainbridge157bdab2020-01-16 14:38:05 -080043 meterModUpdate := openflow_13.MeterModUpdate{Id: ofc.DeviceID}
44 meterMod := openflow_13.OfpMeterMod{
45 MeterId: request.MeterId,
46 Flags: uint32(request.Flags),
47 Command: openflow_13.OfpMeterModCommand(request.Command),
48 }
Don Newtone0d34a82019-11-14 10:58:06 -050049 var bands []*openflow_13.OfpMeterBandHeader
David K. Bainbridge157bdab2020-01-16 14:38:05 -080050 for _, ofpBand := range request.GetMeters() {
Don Newtone0d34a82019-11-14 10:58:06 -050051 var band openflow_13.OfpMeterBandHeader
David K. Bainbridge157bdab2020-01-16 14:38:05 -080052 switch ofpBand.GetType() {
Don Newtone0d34a82019-11-14 10:58:06 -050053 case ofp.OFPMBTDrop:
54 ofpDrop := ofpBand.(ofp.IMeterBandDrop)
Don Newtone0d34a82019-11-14 10:58:06 -050055 band.Type = openflow_13.OfpMeterBandType_OFPMBT_DROP
56 band.Rate = ofpDrop.GetRate()
Don Newtonb437c6f2019-12-18 11:51:57 -050057 band.BurstSize = ofpDrop.GetBurstSize()
Don Newtone0d34a82019-11-14 10:58:06 -050058 case ofp.OFPMBTDSCPRemark:
59 ofpDscpRemark := ofpBand.(ofp.IMeterBandDscpRemark)
60 var dscpRemark openflow_13.OfpMeterBandDscpRemark
61 band.Type = openflow_13.OfpMeterBandType_OFPMBT_DSCP_REMARK
62 band.BurstSize = ofpDscpRemark.GetBurstSize()
63 band.Rate = ofpDscpRemark.GetRate()
64 dscpRemark.PrecLevel = uint32(ofpDscpRemark.GetPrecLevel())
Don Newtonb437c6f2019-12-18 11:51:57 -050065 /*
66 var meterBandHeaderDscp openflow_13.OfpMeterBandHeader_DscpRemark
67 meterBandHeaderDscp.DscpRemark = &dscpRemark
68 band.Data = &meterBandHeaderDscp
69
70 */
Don Newtone0d34a82019-11-14 10:58:06 -050071 case ofp.OFPMBTExperimenter:
72 ofpExperimenter := ofpBand.(ofp.IMeterBandExperimenter)
73 var experimenter openflow_13.OfpMeterBandExperimenter
74 experimenter.Experimenter = ofpExperimenter.GetExperimenter()
75 band.Type = openflow_13.OfpMeterBandType_OFPMBT_EXPERIMENTER
76 band.BurstSize = ofpExperimenter.GetBurstSize()
77 band.Rate = ofpExperimenter.GetRate()
Don Newtonb437c6f2019-12-18 11:51:57 -050078 /*
79 var meterBandHeaderExperimenter openflow_13.OfpMeterBandHeader_Experimenter
80 meterBandHeaderExperimenter.Experimenter = &experimenter
81 band.Data = &meterBandHeaderExperimenter
82
83 */
Don Newtone0d34a82019-11-14 10:58:06 -050084 }
85 bands = append(bands, &band)
86 }
87 meterMod.Bands = bands
88 meterModUpdate.MeterMod = &meterMod
David K. Bainbridge157bdab2020-01-16 14:38:05 -080089 if logger.V(log.DebugLevel) {
Don Newton7577f072020-01-06 12:41:11 -050090 meterModJS, _ := json.Marshal(meterModUpdate)
91 logger.Debugw("handleMeterModUpdate sending request",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080092 log.Fields{
93 "device-id": ofc.DeviceID,
94 "meter-mod-request": meterModJS})
Don Newtone0d34a82019-11-14 10:58:06 -050095 }
David Bainbridgef8ce7d22020-04-08 12:49:41 -070096 if _, err := volthaClient.UpdateLogicalDeviceMeterTable(context.Background(), &meterModUpdate); err != nil {
David K. Bainbridge157bdab2020-01-16 14:38:05 -080097 logger.Errorw("Error calling UpdateLogicalDeviceMeterTable",
98 log.Fields{
99 "device-id": ofc.DeviceID,
100 "error": err})
Don Newton7577f072020-01-06 12:41:11 -0500101 }
Don Newtone0d34a82019-11-14 10:58:06 -0500102}