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 | |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 28 | func (ofc *OFConnection) handleFeatureRequest(ctx context.Context, request *ofp.FeaturesRequest) error { |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 29 | span, ctx := log.CreateChildSpan(ctx, "openflow-feature") |
| 30 | defer span.Finish() |
| 31 | |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 32 | if logger.V(log.DebugLevel) { |
| 33 | js, _ := json.Marshal(request) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 34 | logger.Debugw(ctx, "handleFeatureRequest called", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 35 | log.Fields{ |
| 36 | "device-id": ofc.DeviceID, |
| 37 | "request": js}) |
| 38 | } |
David Bainbridge | f8ce7d2 | 2020-04-08 12:49:41 -0700 | [diff] [blame] | 39 | volthaClient := ofc.VolthaClient.Get() |
| 40 | if volthaClient == nil { |
David K. Bainbridge | 9cb404e | 2020-01-28 14:32:29 -0800 | [diff] [blame] | 41 | return NoVolthaConnectionError |
| 42 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 43 | var id = common.ID{Id: ofc.DeviceID} |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 44 | logicalDevice, err := volthaClient.GetLogicalDevice(log.WithSpanFromContext(context.Background(), ctx), &id) |
David K. Bainbridge | cac73ac | 2020-02-19 07:00:12 -0800 | [diff] [blame] | 45 | if err != nil { |
| 46 | return err |
| 47 | } |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 48 | reply := ofp.NewFeaturesReply() |
| 49 | reply.SetVersion(4) |
| 50 | reply.SetXid(request.GetXid()) |
| 51 | features := logicalDevice.GetSwitchFeatures() |
| 52 | reply.SetDatapathId(logicalDevice.GetDatapathId()) |
| 53 | reply.SetNBuffers(features.GetNBuffers()) |
| 54 | reply.SetNTables(uint8(features.GetNTables())) |
| 55 | reply.SetAuxiliaryId(uint8(features.GetAuxiliaryId())) |
| 56 | capabilities := features.GetCapabilities() |
| 57 | reply.SetCapabilities(ofp.Capabilities(capabilities)) |
| 58 | |
| 59 | if logger.V(log.DebugLevel) { |
| 60 | js, _ := json.Marshal(reply) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 61 | logger.Debugw(ctx, "handleFeatureRequestReturn", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 62 | log.Fields{ |
| 63 | "device-id": ofc.DeviceID, |
| 64 | "reply": js}) |
| 65 | } |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 66 | err = ofc.SendMessage(ctx, reply) |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 67 | return err |
| 68 | } |