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