blob: 7f3b557c3225f90d94f06c852ac6274e2de49f49 [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"
David Bainbridgef8ce7d22020-04-08 12:49:41 -070022
Jonathan Hart828908c2020-04-15 14:23:45 -070023 ofp "github.com/opencord/goloxi/of13"
David K. Bainbridgeaea73cd2020-01-27 10:44:50 -080024 "github.com/opencord/voltha-lib-go/v3/pkg/log"
25 "github.com/opencord/voltha-protos/v3/go/common"
David K. Bainbridge157bdab2020-01-16 14:38:05 -080026)
27
Rohan Agrawalc32d9932020-06-15 11:01:47 +000028func (ofc *OFConnection) handleFeatureRequest(ctx context.Context, request *ofp.FeaturesRequest) error {
David K. Bainbridge157bdab2020-01-16 14:38:05 -080029 if logger.V(log.DebugLevel) {
30 js, _ := json.Marshal(request)
Rohan Agrawalc32d9932020-06-15 11:01:47 +000031 logger.Debugw(ctx, "handleFeatureRequest called",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080032 log.Fields{
33 "device-id": ofc.DeviceID,
34 "request": js})
35 }
David Bainbridgef8ce7d22020-04-08 12:49:41 -070036 volthaClient := ofc.VolthaClient.Get()
37 if volthaClient == nil {
David K. Bainbridge9cb404e2020-01-28 14:32:29 -080038 return NoVolthaConnectionError
39 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -080040 var id = common.ID{Id: ofc.DeviceID}
David Bainbridgef8ce7d22020-04-08 12:49:41 -070041 logicalDevice, err := volthaClient.GetLogicalDevice(context.Background(), &id)
David K. Bainbridgecac73ac2020-02-19 07:00:12 -080042 if err != nil {
43 return err
44 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -080045 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)
Rohan Agrawalc32d9932020-06-15 11:01:47 +000058 logger.Debugw(ctx, "handleFeatureRequestReturn",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080059 log.Fields{
60 "device-id": ofc.DeviceID,
61 "reply": js})
62 }
Rohan Agrawalc32d9932020-06-15 11:01:47 +000063 err = ofc.SendMessage(ctx, reply)
David K. Bainbridge157bdab2020-01-16 14:38:05 -080064 return err
65}