blob: ebfca92759cf01008b6546841d0dec6453c82273 [file] [log] [blame]
Don Newton98fd8812019-09-23 15:15:02 -04001/*
2 Copyright 2017 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"
Don Newton7577f072020-01-06 12:41:11 -050022
23 "github.com/opencord/ofagent-go/settings"
Don Newtonb437c6f2019-12-18 11:51:57 -050024
25 ofp "github.com/donNewtonAlpha/goloxi/of13"
Don Newton7577f072020-01-06 12:41:11 -050026 l "github.com/opencord/voltha-lib-go/v2/pkg/log"
Don Newtonb437c6f2019-12-18 11:51:57 -050027 "github.com/opencord/voltha-protos/v2/go/common"
28 pb "github.com/opencord/voltha-protos/v2/go/voltha"
Don Newton98fd8812019-09-23 15:15:02 -040029)
30
Don Newton7577f072020-01-06 12:41:11 -050031func handleFeatureRequest(request *ofp.FeaturesRequest, DeviceID string, client *Client) error {
32 if settings.GetDebug(DeviceID) {
33 js, _ := json.Marshal(request)
34 logger.Debugw("handleFeatureRequest called", l.Fields{"DeviceID": DeviceID, "request": js})
35 }
Don Newton98fd8812019-09-23 15:15:02 -040036 var grpcClient = *getGrpcClient()
Don Newton7577f072020-01-06 12:41:11 -050037 var id = common.ID{Id: DeviceID}
Don Newton98fd8812019-09-23 15:15:02 -040038 logicalDevice, err := grpcClient.GetLogicalDevice(context.Background(), &id)
39 reply := createFeaturesRequestReply(request.GetXid(), logicalDevice)
Don Newton7577f072020-01-06 12:41:11 -050040
41 if settings.GetDebug(DeviceID) {
42 js, _ := json.Marshal(reply)
43 logger.Debugw("handleFeatureRequestReturn", l.Fields{"DeviceID": DeviceID, "reply": js})
44 }
Don Newton98fd8812019-09-23 15:15:02 -040045 err = client.SendMessage(reply)
46 return err
47}
48func createFeaturesRequestReply(xid uint32, device *pb.LogicalDevice) *ofp.FeaturesReply {
49
50 featureReply := ofp.NewFeaturesReply()
Don Newtone0d34a82019-11-14 10:58:06 -050051 featureReply.SetVersion(4)
Don Newton98fd8812019-09-23 15:15:02 -040052 featureReply.SetXid(xid)
53 features := device.GetSwitchFeatures()
54 featureReply.SetDatapathId(device.GetDatapathId())
55 featureReply.SetNBuffers(features.GetNBuffers())
56 featureReply.SetNTables(uint8(features.GetNTables()))
57 featureReply.SetAuxiliaryId(uint8(features.GetAuxiliaryId()))
58 capabilities := features.GetCapabilities()
59 featureReply.SetCapabilities(ofp.Capabilities(capabilities))
60 return featureReply
61}