blob: 2c01f73450904739a204a2200f10cf78702c9da4 [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"
22 "github.com/opencord/voltha-protos/go/common"
23 pb "github.com/opencord/voltha-protos/go/voltha"
24 ofp "github.com/skydive-project/goloxi/of13"
25 "log"
26)
27
28func handleFeatureRequest(request *ofp.FeaturesRequest, deviceId string, client *Client) error {
29 message, _ := json.Marshal(request)
30 log.Printf("handleFeatureRequest called with %s\n ", message)
31 var grpcClient = *getGrpcClient()
32 var id = common.ID{Id: deviceId}
33 logicalDevice, err := grpcClient.GetLogicalDevice(context.Background(), &id)
34 reply := createFeaturesRequestReply(request.GetXid(), logicalDevice)
35 err = client.SendMessage(reply)
36 return err
37}
38func createFeaturesRequestReply(xid uint32, device *pb.LogicalDevice) *ofp.FeaturesReply {
39
40 featureReply := ofp.NewFeaturesReply()
41 featureReply.SetXid(xid)
42 features := device.GetSwitchFeatures()
43 featureReply.SetDatapathId(device.GetDatapathId())
44 featureReply.SetNBuffers(features.GetNBuffers())
45 featureReply.SetNTables(uint8(features.GetNTables()))
46 featureReply.SetAuxiliaryId(uint8(features.GetAuxiliaryId()))
47 capabilities := features.GetCapabilities()
48 featureReply.SetCapabilities(ofp.Capabilities(capabilities))
49 return featureReply
50}