blob: 5eb8fa036ab40e7c053a48b7caf03fb54f19f8fa [file] [log] [blame]
David K. Bainbridge157bdab2020-01-16 14:38:05 -08001/*
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
17package openflow
18
19import (
20 "context"
21 "encoding/json"
22 ofp "github.com/donNewtonAlpha/goloxi/of13"
David K. Bainbridgeaea73cd2020-01-27 10:44:50 -080023 "github.com/opencord/voltha-lib-go/v3/pkg/log"
24 "github.com/opencord/voltha-protos/v3/go/common"
David K. Bainbridge157bdab2020-01-16 14:38:05 -080025)
26
27func (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. Bainbridge9cb404e2020-01-28 14:32:29 -080035 if ofc.VolthaClient == nil {
36 return NoVolthaConnectionError
37 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -080038 var id = common.ID{Id: ofc.DeviceID}
39 logicalDevice, err := ofc.VolthaClient.GetLogicalDevice(context.Background(), &id)
David K. Bainbridgecac73ac2020-02-19 07:00:12 -080040 if err != nil {
41 return err
42 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -080043 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}