blob: 7e9d816a8b6dd74f913af70cd7a8ccaf0dea0b98 [file] [log] [blame]
Don Newtone0d34a82019-11-14 10:58:06 -05001/*
2 Copyright 2017 the original author or authors.
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*/
16package openflow
17
18import (
19 "encoding/json"
20 ofp "github.com/donNewtonAlpha/goloxi/of13"
Don Newtonb437c6f2019-12-18 11:51:57 -050021 "github.com/opencord/voltha-protos/v2/go/openflow_13"
Don Newtone0d34a82019-11-14 10:58:06 -050022 "golang.org/x/net/context"
23 "log"
24)
25
26func handleMeterModRequest(request *ofp.MeterMod, client *Client) {
27 jsonRequest, _ := json.Marshal(request)
28 log.Printf("handleMeterModRequest called with %s", jsonRequest)
29
30 var meterModUpdate openflow_13.MeterModUpdate
31 meterModUpdate.Id = client.DeviceId
32 var meterMod openflow_13.OfpMeterMod
33 meterMod.MeterId = request.MeterId
34 meterMod.Flags = uint32(request.Flags)
35 command := openflow_13.OfpMeterModCommand(request.Command)
36 meterMod.Command = command
37 var bands []*openflow_13.OfpMeterBandHeader
38 ofpBands := request.GetMeters()
39 for i := 0; i < len(ofpBands); i++ {
40 ofpBand := ofpBands[i]
Don Newtone0d34a82019-11-14 10:58:06 -050041 bandType := ofpBand.GetType()
42 var band openflow_13.OfpMeterBandHeader
43 switch bandType {
44 case ofp.OFPMBTDrop:
45 ofpDrop := ofpBand.(ofp.IMeterBandDrop)
Don Newtone0d34a82019-11-14 10:58:06 -050046 band.Type = openflow_13.OfpMeterBandType_OFPMBT_DROP
47 band.Rate = ofpDrop.GetRate()
Don Newtonb437c6f2019-12-18 11:51:57 -050048 band.BurstSize = ofpDrop.GetBurstSize()
Don Newtone0d34a82019-11-14 10:58:06 -050049 case ofp.OFPMBTDSCPRemark:
50 ofpDscpRemark := ofpBand.(ofp.IMeterBandDscpRemark)
51 var dscpRemark openflow_13.OfpMeterBandDscpRemark
52 band.Type = openflow_13.OfpMeterBandType_OFPMBT_DSCP_REMARK
53 band.BurstSize = ofpDscpRemark.GetBurstSize()
54 band.Rate = ofpDscpRemark.GetRate()
55 dscpRemark.PrecLevel = uint32(ofpDscpRemark.GetPrecLevel())
Don Newtonb437c6f2019-12-18 11:51:57 -050056 /*
57 var meterBandHeaderDscp openflow_13.OfpMeterBandHeader_DscpRemark
58 meterBandHeaderDscp.DscpRemark = &dscpRemark
59 band.Data = &meterBandHeaderDscp
60
61 */
Don Newtone0d34a82019-11-14 10:58:06 -050062 case ofp.OFPMBTExperimenter:
63 ofpExperimenter := ofpBand.(ofp.IMeterBandExperimenter)
64 var experimenter openflow_13.OfpMeterBandExperimenter
65 experimenter.Experimenter = ofpExperimenter.GetExperimenter()
66 band.Type = openflow_13.OfpMeterBandType_OFPMBT_EXPERIMENTER
67 band.BurstSize = ofpExperimenter.GetBurstSize()
68 band.Rate = ofpExperimenter.GetRate()
Don Newtonb437c6f2019-12-18 11:51:57 -050069 /*
70 var meterBandHeaderExperimenter openflow_13.OfpMeterBandHeader_Experimenter
71 meterBandHeaderExperimenter.Experimenter = &experimenter
72 band.Data = &meterBandHeaderExperimenter
73
74 */
Don Newtone0d34a82019-11-14 10:58:06 -050075 }
76 bands = append(bands, &band)
77 }
78 meterMod.Bands = bands
79 meterModUpdate.MeterMod = &meterMod
80 grpcClient := *getGrpcClient()
81 meterModJS, _ := json.Marshal(meterModUpdate)
82 log.Printf("METER MOD UPDATE %s", meterModJS)
83 empty, err := grpcClient.UpdateLogicalDeviceMeterTable(context.Background(), &meterModUpdate)
84 if err != nil {
85 log.Printf("ERROR DOING METER MOD ADD %v", err)
86 }
87 emptyJs, _ := json.Marshal(empty)
88 log.Printf("METER MOD RESPONSE %s", emptyJs)
89}