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" |
| 22 | ofp "github.com/donNewtonAlpha/goloxi/of13" |
David K. Bainbridge | aea73cd | 2020-01-27 10:44:50 -0800 | [diff] [blame] | 23 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 24 | "github.com/opencord/voltha-protos/v3/go/common" |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | func (ofc *OFClient) handleFeatureRequest(request *ofp.FeaturesRequest) error { |
| 28 | if logger.V(log.DebugLevel) { |
| 29 | js, _ := json.Marshal(request) |
| 30 | logger.Debugw("handleFeatureRequest called", |
| 31 | log.Fields{ |
| 32 | "device-id": ofc.DeviceID, |
| 33 | "request": js}) |
| 34 | } |
David K. Bainbridge | 9cb404e | 2020-01-28 14:32:29 -0800 | [diff] [blame] | 35 | if ofc.VolthaClient == nil { |
| 36 | return NoVolthaConnectionError |
| 37 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 38 | var id = common.ID{Id: ofc.DeviceID} |
| 39 | logicalDevice, err := ofc.VolthaClient.GetLogicalDevice(context.Background(), &id) |
David K. Bainbridge | cac73ac | 2020-02-19 07:00:12 -0800 | [diff] [blame] | 40 | if err != nil { |
| 41 | return err |
| 42 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 43 | reply := ofp.NewFeaturesReply() |
| 44 | reply.SetVersion(4) |
| 45 | reply.SetXid(request.GetXid()) |
| 46 | features := logicalDevice.GetSwitchFeatures() |
| 47 | reply.SetDatapathId(logicalDevice.GetDatapathId()) |
| 48 | reply.SetNBuffers(features.GetNBuffers()) |
| 49 | reply.SetNTables(uint8(features.GetNTables())) |
| 50 | reply.SetAuxiliaryId(uint8(features.GetAuxiliaryId())) |
| 51 | capabilities := features.GetCapabilities() |
| 52 | reply.SetCapabilities(ofp.Capabilities(capabilities)) |
| 53 | |
| 54 | if logger.V(log.DebugLevel) { |
| 55 | js, _ := json.Marshal(reply) |
| 56 | logger.Debugw("handleFeatureRequestReturn", |
| 57 | log.Fields{ |
| 58 | "device-id": ofc.DeviceID, |
| 59 | "reply": js}) |
| 60 | } |
| 61 | err = ofc.SendMessage(reply) |
| 62 | return err |
| 63 | } |