David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2020 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 | */ |
| 16 | |
| 17 | package openflow |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "encoding/json" |
Kent Hagerman | 9b0ac0a | 2020-06-08 11:48:16 -0400 | [diff] [blame] | 22 | "net" |
| 23 | |
Jonathan Hart | 828908c | 2020-04-15 14:23:45 -0700 | [diff] [blame] | 24 | "github.com/opencord/goloxi" |
| 25 | ofp "github.com/opencord/goloxi/of13" |
David K. Bainbridge | aea73cd | 2020-01-27 10:44:50 -0800 | [diff] [blame] | 26 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 27 | "github.com/opencord/voltha-protos/v3/go/common" |
| 28 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 29 | ) |
| 30 | |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 31 | func (ofc *OFConnection) handleStatsRequest(ctx context.Context, request ofp.IHeader, statType uint16) error { |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 32 | span, ctx := log.CreateChildSpan(ctx, "openflow-stats") |
| 33 | defer span.Finish() |
| 34 | |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 35 | if logger.V(log.DebugLevel) { |
| 36 | js, _ := json.Marshal(request) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 37 | logger.Debugw(ctx, "handleStatsRequest called", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 38 | log.Fields{ |
| 39 | "device-id": ofc.DeviceID, |
| 40 | "stat-type": statType, |
| 41 | "request": js}) |
| 42 | } |
| 43 | |
| 44 | switch statType { |
| 45 | case ofp.OFPSTDesc: |
| 46 | statsReq := request.(*ofp.DescStatsRequest) |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 47 | response, err := ofc.handleDescStatsRequest(ctx, statsReq) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | if logger.V(log.DebugLevel) { |
| 52 | reqJs, _ := json.Marshal(statsReq) |
| 53 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 54 | logger.Debugw(ctx, "handle-stats-request-desc", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 55 | log.Fields{ |
| 56 | "device-id": ofc.DeviceID, |
| 57 | "request": reqJs, |
| 58 | "response": resJs}) |
| 59 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 60 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 61 | case ofp.OFPSTFlow: |
| 62 | statsReq := request.(*ofp.FlowStatsRequest) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 63 | responses, err := ofc.handleFlowStatsRequest(ctx, statsReq) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 64 | if err != nil { |
| 65 | return err |
| 66 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 67 | if logger.V(log.DebugLevel) { |
| 68 | reqJs, _ := json.Marshal(statsReq) |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 69 | resJs, _ := json.Marshal(responses) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 70 | logger.Debugw(ctx, "handle-stats-request-flow", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 71 | log.Fields{ |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 72 | "device-id": ofc.DeviceID, |
| 73 | "request": reqJs, |
| 74 | "responses-object": responses, |
| 75 | "response": resJs}) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 76 | } |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 77 | for _, response := range responses { |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 78 | err := ofc.SendMessage(ctx, response) |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 79 | if err != nil { |
| 80 | return err |
| 81 | } |
| 82 | } |
| 83 | return nil |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 84 | |
| 85 | case ofp.OFPSTAggregate: |
| 86 | statsReq := request.(*ofp.AggregateStatsRequest) |
| 87 | response, err := ofc.handleAggregateStatsRequest(statsReq) |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 | if logger.V(log.DebugLevel) { |
| 92 | reqJs, _ := json.Marshal(statsReq) |
| 93 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 94 | logger.Debugw(ctx, "handle-stats-request-aggregate", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 95 | log.Fields{ |
| 96 | "device-id": ofc.DeviceID, |
| 97 | "request": reqJs, |
| 98 | "response": resJs}) |
| 99 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 100 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 101 | case ofp.OFPSTTable: |
| 102 | statsReq := request.(*ofp.TableStatsRequest) |
| 103 | response, e := ofc.handleTableStatsRequest(statsReq) |
| 104 | if logger.V(log.DebugLevel) { |
| 105 | reqJs, _ := json.Marshal(statsReq) |
| 106 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 107 | logger.Debugw(ctx, "handle-stats-request-table", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 108 | log.Fields{ |
| 109 | "device-id": ofc.DeviceID, |
| 110 | "request": reqJs, |
| 111 | "response": resJs}) |
| 112 | } |
| 113 | if e != nil { |
| 114 | return e |
| 115 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 116 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 117 | case ofp.OFPSTPort: |
| 118 | statsReq := request.(*ofp.PortStatsRequest) |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 119 | responses, err := ofc.handlePortStatsRequest(ctx, statsReq) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | if logger.V(log.DebugLevel) { |
| 124 | reqJs, _ := json.Marshal(statsReq) |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 125 | resJs, _ := json.Marshal(responses) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 126 | logger.Debugw(ctx, "handle-stats-request-port", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 127 | log.Fields{ |
| 128 | "device-id": ofc.DeviceID, |
| 129 | "request": reqJs, |
| 130 | "response": resJs}) |
| 131 | } |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 132 | for _, response := range responses { |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 133 | err := ofc.SendMessage(ctx, response) |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 134 | if err != nil { |
| 135 | return err |
| 136 | } |
| 137 | } |
| 138 | return nil |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 139 | case ofp.OFPSTQueue: |
| 140 | statsReq := request.(*ofp.QueueStatsRequest) |
| 141 | response, err := ofc.handleQueueStatsRequest(statsReq) |
| 142 | if err != nil { |
| 143 | return err |
| 144 | } |
| 145 | if logger.V(log.DebugLevel) { |
| 146 | reqJs, _ := json.Marshal(statsReq) |
| 147 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 148 | logger.Debugw(ctx, "handle-stats-request-queue", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 149 | log.Fields{ |
| 150 | "device-id": ofc.DeviceID, |
| 151 | "request": reqJs, |
| 152 | "response": resJs}) |
| 153 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 154 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 155 | case ofp.OFPSTGroup: |
| 156 | statsReq := request.(*ofp.GroupStatsRequest) |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 157 | response, err := ofc.handleGroupStatsRequest(ctx, statsReq) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 158 | if err != nil { |
| 159 | return err |
| 160 | } |
| 161 | if logger.V(log.DebugLevel) { |
| 162 | reqJs, _ := json.Marshal(statsReq) |
| 163 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 164 | logger.Debugw(ctx, "handle-stats-request-group", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 165 | log.Fields{ |
| 166 | "device-id": ofc.DeviceID, |
| 167 | "request": reqJs, |
| 168 | "response": resJs}) |
| 169 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 170 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 171 | case ofp.OFPSTGroupDesc: |
| 172 | statsReq := request.(*ofp.GroupDescStatsRequest) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 173 | response, err := ofc.handleGroupStatsDescRequest(ctx, statsReq) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 174 | if err != nil { |
| 175 | return err |
| 176 | } |
| 177 | if logger.V(log.DebugLevel) { |
| 178 | reqJs, _ := json.Marshal(statsReq) |
| 179 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 180 | logger.Debugw(ctx, "handle-stats-request-group-desc", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 181 | log.Fields{ |
| 182 | "device-id": ofc.DeviceID, |
| 183 | "request": reqJs, |
| 184 | "response": resJs}) |
| 185 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 186 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 187 | |
| 188 | case ofp.OFPSTGroupFeatures: |
| 189 | statsReq := request.(*ofp.GroupFeaturesStatsRequest) |
| 190 | response, err := ofc.handleGroupFeatureStatsRequest(statsReq) |
| 191 | if err != nil { |
| 192 | return err |
| 193 | } |
| 194 | if logger.V(log.DebugLevel) { |
| 195 | reqJs, _ := json.Marshal(statsReq) |
| 196 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 197 | logger.Debugw(ctx, "handle-stats-request-group-features", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 198 | log.Fields{ |
| 199 | "device-id": ofc.DeviceID, |
| 200 | "request": reqJs, |
| 201 | "response": resJs}) |
| 202 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 203 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 204 | case ofp.OFPSTMeter: |
| 205 | statsReq := request.(*ofp.MeterStatsRequest) |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 206 | response, err := ofc.handleMeterStatsRequest(ctx, statsReq) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 207 | if err != nil { |
| 208 | return err |
| 209 | } |
| 210 | if logger.V(log.DebugLevel) { |
| 211 | reqJs, _ := json.Marshal(statsReq) |
| 212 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 213 | logger.Debugw(ctx, "handle-stats-request-meter", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 214 | log.Fields{ |
| 215 | "device-id": ofc.DeviceID, |
| 216 | "request": reqJs, |
| 217 | "response": resJs}) |
| 218 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 219 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 220 | case ofp.OFPSTMeterConfig: |
| 221 | statsReq := request.(*ofp.MeterConfigStatsRequest) |
| 222 | response, err := ofc.handleMeterConfigStatsRequest(statsReq) |
| 223 | if err != nil { |
| 224 | return err |
| 225 | } |
| 226 | if logger.V(log.DebugLevel) { |
| 227 | reqJs, _ := json.Marshal(statsReq) |
| 228 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 229 | logger.Debugw(ctx, "handle-stats-request-meter-config", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 230 | log.Fields{ |
| 231 | "device-id": ofc.DeviceID, |
| 232 | "request": reqJs, |
| 233 | "response": resJs}) |
| 234 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 235 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 236 | case ofp.OFPSTMeterFeatures: |
| 237 | statsReq := request.(*ofp.MeterFeaturesStatsRequest) |
| 238 | response, err := ofc.handleMeterFeatureStatsRequest(statsReq) |
| 239 | if err != nil { |
| 240 | return err |
| 241 | } |
| 242 | if logger.V(log.DebugLevel) { |
| 243 | reqJs, _ := json.Marshal(statsReq) |
| 244 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 245 | logger.Debugw(ctx, "handle-stats-request-meter-features", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 246 | log.Fields{ |
| 247 | "device-id": ofc.DeviceID, |
| 248 | "request": reqJs, |
| 249 | "response": resJs}) |
| 250 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 251 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 252 | case ofp.OFPSTTableFeatures: |
| 253 | statsReq := request.(*ofp.TableFeaturesStatsRequest) |
| 254 | response, err := ofc.handleTableFeaturesStatsRequest(statsReq) |
| 255 | if err != nil { |
| 256 | return err |
| 257 | } |
| 258 | if logger.V(log.DebugLevel) { |
| 259 | reqJs, _ := json.Marshal(statsReq) |
| 260 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 261 | logger.Debugw(ctx, "handle-stats-request-table-features", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 262 | log.Fields{ |
| 263 | "device-id": ofc.DeviceID, |
| 264 | "request": reqJs, |
| 265 | "response": resJs}) |
| 266 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 267 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 268 | case ofp.OFPSTPortDesc: |
| 269 | statsReq := request.(*ofp.PortDescStatsRequest) |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 270 | responses, err := ofc.handlePortDescStatsRequest(ctx, statsReq) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 271 | if err != nil { |
| 272 | return err |
| 273 | } |
| 274 | if logger.V(log.DebugLevel) { |
| 275 | reqJs, _ := json.Marshal(statsReq) |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 276 | resJs, _ := json.Marshal(responses) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 277 | logger.Debugw(ctx, "handle-stats-request-port-desc", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 278 | log.Fields{ |
| 279 | "device-id": ofc.DeviceID, |
| 280 | "request": reqJs, |
| 281 | "response": resJs}) |
| 282 | } |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 283 | for _, response := range responses { |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 284 | err := ofc.SendMessage(ctx, response) |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 285 | if err != nil { |
| 286 | return err |
| 287 | } |
| 288 | } |
| 289 | return nil |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 290 | |
| 291 | case ofp.OFPSTExperimenter: |
| 292 | statsReq := request.(*ofp.ExperimenterStatsRequest) |
| 293 | response, err := ofc.handleExperimenterStatsRequest(statsReq) |
| 294 | if err != nil { |
| 295 | return err |
| 296 | } |
| 297 | if logger.V(log.DebugLevel) { |
| 298 | reqJs, _ := json.Marshal(statsReq) |
| 299 | resJs, _ := json.Marshal(response) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 300 | logger.Debugw(ctx, "handle-stats-request-experimenter", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 301 | log.Fields{ |
| 302 | "device-id": ofc.DeviceID, |
| 303 | "request": reqJs, |
| 304 | "response": resJs}) |
| 305 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 306 | return ofc.SendMessage(ctx, response) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 307 | } |
| 308 | return nil |
| 309 | } |
| 310 | |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 311 | func (ofc *OFConnection) handleDescStatsRequest(ctx context.Context, request *ofp.DescStatsRequest) (*ofp.DescStatsReply, error) { |
David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 312 | volthaClient := ofc.VolthaClient.Get() |
| 313 | if volthaClient == nil { |
David K. Bainbridge | 9cb404e | 2020-01-28 14:32:29 -0800 | [diff] [blame] | 314 | return nil, NoVolthaConnectionError |
| 315 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 316 | response := ofp.NewDescStatsReply() |
| 317 | response.SetXid(request.GetXid()) |
| 318 | response.SetVersion(request.GetVersion()) |
| 319 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 320 | |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 321 | resp, err := volthaClient.GetLogicalDevice(log.WithSpanFromContext(context.Background(), ctx), |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 322 | &common.ID{Id: ofc.DeviceID}) |
| 323 | if err != nil { |
| 324 | return nil, err |
| 325 | } |
| 326 | desc := resp.GetDesc() |
| 327 | |
| 328 | response.SetMfrDesc(PadString(desc.GetMfrDesc(), 256)) |
| 329 | response.SetHwDesc(PadString(desc.GetHwDesc(), 256)) |
| 330 | response.SetSwDesc(PadString(desc.GetSwDesc(), 256)) |
| 331 | response.SetSerialNum(PadString(desc.GetSerialNum(), 32)) |
| 332 | response.SetDpDesc(PadString(desc.GetDpDesc(), 256)) |
| 333 | return response, nil |
| 334 | } |
| 335 | |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 336 | func (ofc *OFConnection) handleFlowStatsRequest(ctx context.Context, request *ofp.FlowStatsRequest) ([]*ofp.FlowStatsReply, error) { |
David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 337 | volthaClient := ofc.VolthaClient.Get() |
| 338 | if volthaClient == nil { |
David K. Bainbridge | 9cb404e | 2020-01-28 14:32:29 -0800 | [diff] [blame] | 339 | return nil, NoVolthaConnectionError |
| 340 | } |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 341 | resp, err := volthaClient.ListLogicalDeviceFlows(log.WithSpanFromContext(context.Background(), ctx), |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 342 | &common.ID{Id: ofc.DeviceID}) |
| 343 | if err != nil { |
| 344 | return nil, err |
| 345 | } |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 346 | var flows []*ofp.FlowStatsEntry |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 347 | for _, item := range resp.GetItems() { |
| 348 | entry := ofp.NewFlowStatsEntry() |
| 349 | entry.SetTableId(uint8(item.GetTableId())) |
| 350 | entry.SetDurationSec(item.GetDurationSec()) |
| 351 | entry.SetDurationNsec(item.GetDurationNsec()) |
| 352 | entry.SetPriority(uint16(item.GetPriority())) |
| 353 | entry.SetIdleTimeout(uint16(item.GetIdleTimeout())) |
| 354 | entry.SetHardTimeout(uint16(item.GetHardTimeout())) |
| 355 | entry.SetFlags(ofp.FlowModFlags(item.GetFlags())) |
| 356 | entry.SetCookie(item.GetCookie()) |
| 357 | entry.SetPacketCount(item.GetPacketCount()) |
| 358 | entry.SetByteCount(item.GetByteCount()) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 359 | match := ofp.NewMatchV3() |
| 360 | pbMatch := item.GetMatch() |
| 361 | match.SetType(uint16(pbMatch.GetType())) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 362 | var fields []goloxi.IOxm |
| 363 | for _, oxmField := range pbMatch.GetOxmFields() { |
| 364 | field := oxmField.GetField() |
| 365 | ofbField := field.(*openflow_13.OfpOxmField_OfbField).OfbField |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 366 | iOxm := parseOxm(ctx, ofbField) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 367 | fields = append(fields, iOxm) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | match.OxmList = fields |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 371 | entry.SetMatch(*match) |
| 372 | var instructions []ofp.IInstruction |
| 373 | for _, ofpInstruction := range item.Instructions { |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 374 | instruction := parseInstructions(ctx, ofpInstruction) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 375 | instructions = append(instructions, instruction) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 376 | } |
| 377 | entry.Instructions = instructions |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 378 | flows = append(flows, entry) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 379 | } |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 380 | var responses []*ofp.FlowStatsReply |
Matteo Scandolo | 256266d | 2020-06-01 13:44:07 -0700 | [diff] [blame] | 381 | chunkSize := ofc.flowsChunkSize |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 382 | total := len(flows) / chunkSize |
| 383 | n := 0 |
| 384 | for n <= total { |
| 385 | |
Andrea Campanella | f2cf13e | 2020-09-03 16:22:27 +0200 | [diff] [blame] | 386 | limit := (n * chunkSize) + chunkSize |
| 387 | |
| 388 | chunk := flows[n*chunkSize : min(limit, len(flows))] |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 389 | |
| 390 | if len(chunk) == 0 { |
| 391 | break |
| 392 | } |
| 393 | |
| 394 | response := ofp.NewFlowStatsReply() |
| 395 | response.SetXid(request.GetXid()) |
| 396 | response.SetVersion(4) |
| 397 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
Andrea Campanella | f2cf13e | 2020-09-03 16:22:27 +0200 | [diff] [blame] | 398 | if limit < len(flows) { |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 399 | response.SetFlags(ofp.StatsReplyFlags(ofp.OFPSFReplyMore)) |
| 400 | } |
| 401 | response.SetEntries(chunk) |
| 402 | responses = append(responses, response) |
| 403 | n++ |
| 404 | } |
| 405 | return responses, nil |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 408 | func (ofc *OFConnection) handleAggregateStatsRequest(request *ofp.AggregateStatsRequest) (*ofp.AggregateStatsReply, error) { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 409 | response := ofp.NewAggregateStatsReply() |
| 410 | response.SetVersion(request.GetVersion()) |
| 411 | response.SetXid(request.GetXid()) |
| 412 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 413 | response.SetFlowCount(0) |
| 414 | //TODO wire this to voltha core when it implements |
| 415 | return response, nil |
| 416 | } |
| 417 | |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 418 | func (ofc *OFConnection) handleGroupStatsRequest(ctx context.Context, request *ofp.GroupStatsRequest) (*ofp.GroupStatsReply, error) { |
David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 419 | volthaClient := ofc.VolthaClient.Get() |
| 420 | if volthaClient == nil { |
David K. Bainbridge | 9cb404e | 2020-01-28 14:32:29 -0800 | [diff] [blame] | 421 | return nil, NoVolthaConnectionError |
| 422 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 423 | response := ofp.NewGroupStatsReply() |
| 424 | response.SetVersion(request.GetVersion()) |
| 425 | response.SetXid(request.GetXid()) |
| 426 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 427 | reply, err := volthaClient.ListLogicalDeviceFlowGroups(log.WithSpanFromContext(context.Background(), ctx), |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 428 | &common.ID{Id: ofc.DeviceID}) |
| 429 | if err != nil { |
| 430 | return nil, err |
| 431 | } |
| 432 | |
| 433 | var groupStatsEntries []*ofp.GroupStatsEntry |
| 434 | for _, item := range reply.GetItems() { |
| 435 | stats := item.GetStats() |
| 436 | var entry ofp.GroupStatsEntry |
| 437 | entry.SetByteCount(stats.GetByteCount()) |
| 438 | entry.SetPacketCount(stats.GetPacketCount()) |
| 439 | entry.SetDurationNsec(stats.GetDurationNsec()) |
| 440 | entry.SetDurationSec(stats.GetDurationSec()) |
| 441 | entry.SetRefCount(stats.GetRefCount()) |
| 442 | entry.SetGroupId(stats.GetGroupId()) |
| 443 | var bucketStatsList []*ofp.BucketCounter |
Jonathan Hart | 60c5d77 | 2020-03-30 18:28:40 -0700 | [diff] [blame] | 444 | // TODO fix this when API handler is fixed in the core |
| 445 | // Core doesn't return any buckets in the Stats object, so just |
| 446 | // fill out an empty BucketCounter for each bucket in the group Desc for now. |
| 447 | for range item.GetDesc().GetBuckets() { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 448 | bucketCounter := ofp.BucketCounter{} |
Jonathan Hart | 60c5d77 | 2020-03-30 18:28:40 -0700 | [diff] [blame] | 449 | bucketCounter.SetPacketCount(0) |
| 450 | bucketCounter.SetByteCount(0) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 451 | bucketStatsList = append(bucketStatsList, &bucketCounter) |
| 452 | } |
| 453 | entry.SetBucketStats(bucketStatsList) |
| 454 | groupStatsEntries = append(groupStatsEntries, &entry) |
| 455 | } |
| 456 | response.SetEntries(groupStatsEntries) |
| 457 | return response, nil |
| 458 | } |
| 459 | |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 460 | func (ofc *OFConnection) handleGroupStatsDescRequest(ctx context.Context, request *ofp.GroupDescStatsRequest) (*ofp.GroupDescStatsReply, error) { |
David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 461 | volthaClient := ofc.VolthaClient.Get() |
| 462 | if volthaClient == nil { |
David K. Bainbridge | 9cb404e | 2020-01-28 14:32:29 -0800 | [diff] [blame] | 463 | return nil, NoVolthaConnectionError |
| 464 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 465 | response := ofp.NewGroupDescStatsReply() |
| 466 | response.SetVersion(request.GetVersion()) |
| 467 | response.SetXid(request.GetXid()) |
| 468 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 469 | reply, err := volthaClient.ListLogicalDeviceFlowGroups(log.WithSpanFromContext(context.Background(), ctx), |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 470 | &common.ID{Id: ofc.DeviceID}) |
| 471 | if err != nil { |
| 472 | return nil, err |
| 473 | } |
| 474 | var groupDescStatsEntries []*ofp.GroupDescStatsEntry |
| 475 | for _, item := range reply.GetItems() { |
Jonathan Hart | 60c5d77 | 2020-03-30 18:28:40 -0700 | [diff] [blame] | 476 | desc := item.GetDesc() |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 477 | |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 478 | buckets := volthaBucketsToOpenflow(ctx, desc.Buckets) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 479 | |
Jonathan Hart | 60c5d77 | 2020-03-30 18:28:40 -0700 | [diff] [blame] | 480 | groupDesc := &ofp.GroupDescStatsEntry{ |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 481 | GroupType: volthaGroupTypeToOpenflow(ctx, desc.Type), |
Jonathan Hart | 60c5d77 | 2020-03-30 18:28:40 -0700 | [diff] [blame] | 482 | GroupId: desc.GroupId, |
| 483 | Buckets: buckets, |
| 484 | } |
| 485 | groupDescStatsEntries = append(groupDescStatsEntries, groupDesc) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 486 | } |
| 487 | response.SetEntries(groupDescStatsEntries) |
| 488 | return response, nil |
| 489 | } |
| 490 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 491 | func (ofc *OFConnection) handleGroupFeatureStatsRequest(request *ofp.GroupFeaturesStatsRequest) (*ofp.GroupFeaturesStatsReply, error) { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 492 | response := ofp.NewGroupFeaturesStatsReply() |
| 493 | response.SetVersion(request.GetVersion()) |
| 494 | response.SetXid(request.GetXid()) |
| 495 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 496 | //TODO wire this to voltha core when it implements |
| 497 | return response, nil |
| 498 | } |
| 499 | |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 500 | func (ofc *OFConnection) handleMeterStatsRequest(ctx context.Context, request *ofp.MeterStatsRequest) (*ofp.MeterStatsReply, error) { |
David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 501 | volthaClient := ofc.VolthaClient.Get() |
| 502 | if volthaClient == nil { |
David K. Bainbridge | 9cb404e | 2020-01-28 14:32:29 -0800 | [diff] [blame] | 503 | return nil, NoVolthaConnectionError |
| 504 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 505 | response := ofp.NewMeterStatsReply() |
| 506 | response.SetVersion(request.GetVersion()) |
| 507 | response.SetXid(request.GetXid()) |
| 508 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 509 | resp, err := volthaClient.ListLogicalDeviceMeters(log.WithSpanFromContext(context.Background(), ctx), |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 510 | &common.ID{Id: ofc.DeviceID}) |
| 511 | if err != nil { |
| 512 | return nil, err |
| 513 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 514 | var meterStats []*ofp.MeterStats |
| 515 | for _, item := range resp.Items { |
| 516 | meterStat := ofp.NewMeterStats() |
| 517 | stats := item.Stats |
| 518 | meterStat.DurationNsec = stats.DurationNsec |
| 519 | meterStat.DurationSec = stats.DurationSec |
| 520 | meterStat.ByteInCount = stats.ByteInCount |
| 521 | meterStat.FlowCount = stats.FlowCount |
| 522 | meterStat.MeterId = stats.MeterId |
| 523 | var bandStats []*ofp.MeterBandStats |
| 524 | for _, bStat := range stats.BandStats { |
| 525 | bandStat := ofp.NewMeterBandStats() |
| 526 | bandStat.ByteBandCount = bStat.ByteBandCount |
| 527 | bandStat.PacketBandCount = bStat.PacketBandCount |
| 528 | bandStats = append(bandStats, bandStat) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 529 | } |
| 530 | meterStat.SetBandStats(bandStats) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 531 | meterStats = append(meterStats, meterStat) |
| 532 | } |
| 533 | response.SetEntries(meterStats) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 534 | return response, nil |
| 535 | } |
| 536 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 537 | func (ofc *OFConnection) handleMeterConfigStatsRequest(request *ofp.MeterConfigStatsRequest) (*ofp.MeterConfigStatsReply, error) { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 538 | response := ofp.NewMeterConfigStatsReply() |
| 539 | response.SetVersion(request.GetVersion()) |
| 540 | response.SetXid(request.GetXid()) |
| 541 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 542 | //TODO wire this to voltha core when it implements |
| 543 | return response, nil |
| 544 | } |
| 545 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 546 | func (ofc *OFConnection) handleTableFeaturesStatsRequest(request *ofp.TableFeaturesStatsRequest) (*ofp.TableFeaturesStatsReply, error) { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 547 | response := ofp.NewTableFeaturesStatsReply() |
| 548 | response.SetVersion(request.GetVersion()) |
| 549 | response.SetXid(request.GetXid()) |
| 550 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 551 | //TODO wire this to voltha core when it implements |
| 552 | return response, nil |
| 553 | } |
| 554 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 555 | func (ofc *OFConnection) handleTableStatsRequest(request *ofp.TableStatsRequest) (*ofp.TableStatsReply, error) { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 556 | var response = ofp.NewTableStatsReply() |
| 557 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 558 | response.SetVersion(request.GetVersion()) |
| 559 | response.SetXid(request.GetXid()) |
| 560 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 561 | return response, nil |
| 562 | } |
| 563 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 564 | func (ofc *OFConnection) handleQueueStatsRequest(request *ofp.QueueStatsRequest) (*ofp.QueueStatsReply, error) { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 565 | response := ofp.NewQueueStatsReply() |
| 566 | response.SetVersion(request.GetVersion()) |
| 567 | response.SetXid(request.GetXid()) |
| 568 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 569 | //TODO wire this to voltha core when it implements |
| 570 | return response, nil |
| 571 | } |
| 572 | |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 573 | func (ofc *OFConnection) handlePortStatsRequest(ctx context.Context, request *ofp.PortStatsRequest) ([]*ofp.PortStatsReply, error) { |
David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 574 | volthaClient := ofc.VolthaClient.Get() |
| 575 | if volthaClient == nil { |
David K. Bainbridge | 9cb404e | 2020-01-28 14:32:29 -0800 | [diff] [blame] | 576 | return nil, NoVolthaConnectionError |
| 577 | } |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 578 | |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 579 | reply, err := volthaClient.ListLogicalDevicePorts(log.WithSpanFromContext(context.Background(), ctx), |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 580 | &common.ID{Id: ofc.DeviceID}) |
| 581 | if err != nil { |
| 582 | return nil, err |
| 583 | } |
| 584 | var entries []*ofp.PortStatsEntry |
| 585 | if request.GetPortNo() == 0xffffffff { //all ports |
| 586 | for _, port := range reply.GetItems() { |
| 587 | entries = append(entries, parsePortStats(port)) |
| 588 | } |
| 589 | } else { //find right port that is requested |
| 590 | for _, port := range reply.GetItems() { |
| 591 | if port.GetOfpPortStats().GetPortNo() == uint32(request.GetPortNo()) { |
| 592 | entries = append(entries, parsePortStats(port)) |
| 593 | } |
| 594 | } |
| 595 | } |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 596 | |
| 597 | var responses []*ofp.PortStatsReply |
Matteo Scandolo | 256266d | 2020-06-01 13:44:07 -0700 | [diff] [blame] | 598 | chunkSize := ofc.portsChunkSize |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 599 | total := len(entries) / chunkSize |
| 600 | n := 0 |
| 601 | for n <= total { |
| 602 | |
| 603 | chunk := entries[n*chunkSize : min((n*chunkSize)+chunkSize, len(entries))] |
| 604 | |
| 605 | if len(chunk) == 0 { |
| 606 | break |
| 607 | } |
| 608 | |
| 609 | response := ofp.NewPortStatsReply() |
| 610 | response.SetXid(request.GetXid()) |
| 611 | response.SetVersion(request.GetVersion()) |
| 612 | if total != n { |
| 613 | response.SetFlags(ofp.StatsReplyFlags(ofp.OFPSFReplyMore)) |
| 614 | } |
| 615 | response.SetEntries(entries[n*chunkSize : min((n*chunkSize)+chunkSize, len(entries))]) |
| 616 | responses = append(responses, response) |
| 617 | n++ |
| 618 | } |
| 619 | return responses, nil |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 620 | } |
| 621 | |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 622 | func (ofc *OFConnection) handlePortDescStatsRequest(ctx context.Context, request *ofp.PortDescStatsRequest) ([]*ofp.PortDescStatsReply, error) { |
David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 623 | volthaClient := ofc.VolthaClient.Get() |
| 624 | if volthaClient == nil { |
David K. Bainbridge | 9cb404e | 2020-01-28 14:32:29 -0800 | [diff] [blame] | 625 | return nil, NoVolthaConnectionError |
| 626 | } |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 627 | |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 628 | ports, err := volthaClient.ListLogicalDevicePorts(log.WithSpanFromContext(context.Background(), ctx), &common.ID{Id: ofc.DeviceID}) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 629 | if err != nil { |
| 630 | return nil, err |
| 631 | } |
| 632 | var entries []*ofp.PortDesc |
Kent Hagerman | 9b0ac0a | 2020-06-08 11:48:16 -0400 | [diff] [blame] | 633 | for _, port := range ports.Items { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 634 | ofpPort := port.GetOfpPort() |
| 635 | var entry ofp.PortDesc |
| 636 | entry.SetPortNo(ofp.Port(ofpPort.GetPortNo())) |
| 637 | |
| 638 | var octets []byte |
| 639 | for _, val := range ofpPort.GetHwAddr() { |
| 640 | octets = append(octets, byte(val)) |
| 641 | } |
| 642 | hwAddr := net.HardwareAddr(octets) |
| 643 | entry.SetHwAddr(hwAddr) |
| 644 | entry.SetName(PadString(ofpPort.GetName(), 16)) |
| 645 | entry.SetConfig(ofp.PortConfig(ofpPort.GetConfig())) |
| 646 | entry.SetState(ofp.PortState(ofpPort.GetState())) |
| 647 | entry.SetCurr(ofp.PortFeatures(ofpPort.GetCurr())) |
| 648 | entry.SetAdvertised(ofp.PortFeatures(ofpPort.GetAdvertised())) |
| 649 | entry.SetSupported(ofp.PortFeatures(ofpPort.GetSupported())) |
| 650 | entry.SetPeer(ofp.PortFeatures(ofpPort.GetPeer())) |
| 651 | entry.SetCurrSpeed(ofpPort.GetCurrSpeed()) |
| 652 | entry.SetMaxSpeed(ofpPort.GetMaxSpeed()) |
| 653 | |
| 654 | entries = append(entries, &entry) |
| 655 | } |
| 656 | |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 657 | var responses []*ofp.PortDescStatsReply |
Matteo Scandolo | 256266d | 2020-06-01 13:44:07 -0700 | [diff] [blame] | 658 | chunkSize := ofc.portsDescChunkSize |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 659 | total := len(entries) / chunkSize |
| 660 | n := 0 |
| 661 | for n <= total { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 662 | |
Matteo Scandolo | e23b758 | 2020-05-21 13:50:02 -0700 | [diff] [blame] | 663 | chunk := entries[n*chunkSize : min((n*chunkSize)+chunkSize, len(entries))] |
| 664 | |
| 665 | if len(chunk) == 0 { |
| 666 | break |
| 667 | } |
| 668 | |
| 669 | response := ofp.NewPortDescStatsReply() |
| 670 | response.SetVersion(request.GetVersion()) |
| 671 | response.SetXid(request.GetXid()) |
| 672 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 673 | if total != n { |
| 674 | response.SetFlags(ofp.StatsReplyFlags(ofp.OFPSFReplyMore)) |
| 675 | } |
| 676 | response.SetEntries(chunk) |
| 677 | responses = append(responses, response) |
| 678 | n++ |
| 679 | } |
| 680 | return responses, nil |
| 681 | |
| 682 | } |
| 683 | |
| 684 | // Interestingly enough there is no min function fot two integers |
| 685 | func min(a, b int) int { |
| 686 | if a < b { |
| 687 | return a |
| 688 | } |
| 689 | return b |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 690 | } |
| 691 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 692 | func (ofc *OFConnection) handleMeterFeatureStatsRequest(request *ofp.MeterFeaturesStatsRequest) (*ofp.MeterFeaturesStatsReply, error) { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 693 | response := ofp.NewMeterFeaturesStatsReply() |
| 694 | response.SetXid(request.GetXid()) |
| 695 | response.SetVersion(request.GetVersion()) |
| 696 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 697 | meterFeatures := ofp.NewMeterFeatures() |
| 698 | meterFeatures.Capabilities = ofp.OFPMFKbps |
| 699 | meterFeatures.BandTypes = ofp.OFPMBTDrop |
| 700 | meterFeatures.MaxMeter = 0xffffffff |
| 701 | meterFeatures.MaxBands = 0xff |
| 702 | meterFeatures.MaxColor = 0xff |
| 703 | response.Features = *meterFeatures |
| 704 | return response, nil |
| 705 | } |
| 706 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 707 | func (ofc *OFConnection) handleExperimenterStatsRequest(request *ofp.ExperimenterStatsRequest) (*ofp.ExperimenterStatsReply, error) { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 708 | response := ofp.NewExperimenterStatsReply(request.GetExperimenter()) |
| 709 | response.SetVersion(request.GetVersion()) |
| 710 | response.SetXid(request.GetXid()) |
| 711 | response.SetFlags(ofp.StatsReplyFlags(request.GetFlags())) |
| 712 | //TODO wire this to voltha core when it implements |
| 713 | return response, nil |
| 714 | } |