blob: ee8d900805491a5df60caadc12097c15c657e5e3 [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"
Andrea Campanella18448bc2021-07-08 18:47:22 +020024 "github.com/opencord/voltha-lib-go/v5/pkg/log"
Maninder12b909f2020-10-23 14:23:36 +053025 "github.com/opencord/voltha-protos/v4/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 {
Girish Kumar01e0c632020-08-10 16:48:56 +000029 span, ctx := log.CreateChildSpan(ctx, "openflow-feature")
30 defer span.Finish()
31
David K. Bainbridge157bdab2020-01-16 14:38:05 -080032 if logger.V(log.DebugLevel) {
33 js, _ := json.Marshal(request)
Rohan Agrawalc32d9932020-06-15 11:01:47 +000034 logger.Debugw(ctx, "handleFeatureRequest called",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080035 log.Fields{
36 "device-id": ofc.DeviceID,
37 "request": js})
38 }
David Bainbridgef8ce7d22020-04-08 12:49:41 -070039 volthaClient := ofc.VolthaClient.Get()
40 if volthaClient == nil {
David K. Bainbridge9cb404e2020-01-28 14:32:29 -080041 return NoVolthaConnectionError
42 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -080043 var id = common.ID{Id: ofc.DeviceID}
Girish Kumar01e0c632020-08-10 16:48:56 +000044 logicalDevice, err := volthaClient.GetLogicalDevice(log.WithSpanFromContext(context.Background(), ctx), &id)
David K. Bainbridgecac73ac2020-02-19 07:00:12 -080045 if err != nil {
46 return err
47 }
David K. Bainbridge157bdab2020-01-16 14:38:05 -080048 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 Agrawalc32d9932020-06-15 11:01:47 +000061 logger.Debugw(ctx, "handleFeatureRequestReturn",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080062 log.Fields{
63 "device-id": ofc.DeviceID,
64 "reply": js})
65 }
Rohan Agrawalc32d9932020-06-15 11:01:47 +000066 err = ofc.SendMessage(ctx, reply)
David K. Bainbridge157bdab2020-01-16 14:38:05 -080067 return err
68}