khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 17 | package core |
| 18 | |
| 19 | import ( |
| 20 | "context" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 21 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 22 | "github.com/golang/protobuf/ptypes" |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 23 | a "github.com/golang/protobuf/ptypes/any" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 24 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 25 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 26 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 27 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 28 | "github.com/opencord/voltha-protos/v3/go/voltha" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 29 | "google.golang.org/grpc/codes" |
| 30 | "google.golang.org/grpc/status" |
| 31 | ) |
| 32 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 33 | // AdapterProxy represents adapter proxy attributes |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 34 | type AdapterProxy struct { |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 35 | TestMode bool |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 36 | deviceTopicRegistered bool |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 37 | corePairTopic string |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 38 | kafkaICProxy kafka.InterContainerProxy |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 39 | } |
| 40 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 41 | // NewAdapterProxy will return adapter proxy instance |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 42 | func NewAdapterProxy(kafkaProxy kafka.InterContainerProxy, corePairTopic string) *AdapterProxy { |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 43 | return &AdapterProxy{ |
| 44 | kafkaICProxy: kafkaProxy, |
| 45 | corePairTopic: corePairTopic, |
| 46 | deviceTopicRegistered: false, |
| 47 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 48 | } |
| 49 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 50 | func unPackResponse(rpc string, deviceID string, success bool, response *a.Any) error { |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 51 | if success { |
| 52 | return nil |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 53 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 54 | unpackResult := &ic.Error{} |
| 55 | var err error |
| 56 | if err = ptypes.UnmarshalAny(response, unpackResult); err != nil { |
| 57 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 58 | return err |
| 59 | } |
| 60 | log.Debugw("response", log.Fields{"rpc": rpc, "deviceId": deviceID, "success": success, "error": err}) |
| 61 | // TODO: Need to get the real error code |
| 62 | return status.Errorf(codes.Canceled, "%s", unpackResult.Reason) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 63 | } |
| 64 | |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 65 | func (ap *AdapterProxy) getCoreTopic() kafka.Topic { |
Kent Hagerman | a6d0c36 | 2019-07-30 12:50:21 -0400 | [diff] [blame] | 66 | return kafka.Topic{Name: ap.corePairTopic} |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 67 | } |
| 68 | |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 69 | func (ap *AdapterProxy) getAdapterTopic(adapterName string) kafka.Topic { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 70 | return kafka.Topic{Name: adapterName} |
| 71 | } |
| 72 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 73 | // AdoptDevice invokes adopt device rpc |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 74 | func (ap *AdapterProxy) AdoptDevice(ctx context.Context, device *voltha.Device) error { |
| 75 | log.Debugw("AdoptDevice", log.Fields{"device": device}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 76 | rpc := "adopt_device" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 77 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 78 | //topic := kafka.Topic{Name: device.Adapter} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 79 | args := make([]*kafka.KVArg, 1) |
| 80 | args[0] = &kafka.KVArg{ |
| 81 | Key: "device", |
| 82 | Value: device, |
| 83 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 84 | // Use a device topic for the response as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 85 | replyToTopic := ap.getCoreTopic() |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 86 | ap.deviceTopicRegistered = true |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 87 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 88 | log.Debugw("AdoptDevice-response", log.Fields{"replyTopic": replyToTopic, "deviceid": device.Id, "success": success}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 89 | return unPackResponse(rpc, device.Id, success, result) |
| 90 | } |
| 91 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 92 | // DisableDevice invokes disable device rpc |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 93 | func (ap *AdapterProxy) DisableDevice(ctx context.Context, device *voltha.Device) error { |
| 94 | log.Debugw("DisableDevice", log.Fields{"deviceId": device.Id}) |
| 95 | rpc := "disable_device" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 96 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 97 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 98 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 99 | // specific topic |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 100 | //toTopic := kafka.CreateSubTopic(device.Adapter, device.Id) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 101 | args := make([]*kafka.KVArg, 1) |
| 102 | args[0] = &kafka.KVArg{ |
| 103 | Key: "device", |
| 104 | Value: device, |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 105 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 106 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 107 | //replyToTopic := kafka.CreateSubTopic(ap.kafkaICProxy.DefaultTopic.Name, device.Id) |
| 108 | replyToTopic := ap.getCoreTopic() |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 109 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 110 | log.Debugw("DisableDevice-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 111 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 112 | } |
| 113 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 114 | // ReEnableDevice invokes reenable device rpc |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 115 | func (ap *AdapterProxy) ReEnableDevice(ctx context.Context, device *voltha.Device) error { |
| 116 | log.Debugw("ReEnableDevice", log.Fields{"deviceId": device.Id}) |
| 117 | rpc := "reenable_device" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 118 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 119 | args := make([]*kafka.KVArg, 1) |
| 120 | args[0] = &kafka.KVArg{ |
| 121 | Key: "device", |
| 122 | Value: device, |
| 123 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 124 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 125 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 126 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 127 | log.Debugw("ReEnableDevice-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 128 | return unPackResponse(rpc, device.Id, success, result) |
| 129 | } |
| 130 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 131 | // RebootDevice invokes reboot device rpc |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 132 | func (ap *AdapterProxy) RebootDevice(ctx context.Context, device *voltha.Device) error { |
| 133 | log.Debugw("RebootDevice", log.Fields{"deviceId": device.Id}) |
| 134 | rpc := "reboot_device" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 135 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 136 | args := make([]*kafka.KVArg, 1) |
| 137 | args[0] = &kafka.KVArg{ |
| 138 | Key: "device", |
| 139 | Value: device, |
| 140 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 141 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 142 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 143 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 144 | log.Debugw("RebootDevice-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 145 | return unPackResponse(rpc, device.Id, success, result) |
| 146 | } |
| 147 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 148 | // DeleteDevice invokes delete device rpc |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 149 | func (ap *AdapterProxy) DeleteDevice(ctx context.Context, device *voltha.Device) error { |
| 150 | log.Debugw("DeleteDevice", log.Fields{"deviceId": device.Id}) |
| 151 | rpc := "delete_device" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 152 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 153 | args := make([]*kafka.KVArg, 1) |
| 154 | args[0] = &kafka.KVArg{ |
| 155 | Key: "device", |
| 156 | Value: device, |
| 157 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 158 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 159 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 160 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 161 | log.Debugw("DeleteDevice-response", log.Fields{"deviceid": device.Id, "success": success}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 162 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 163 | return unPackResponse(rpc, device.Id, success, result) |
| 164 | } |
| 165 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 166 | // GetOfpDeviceInfo invokes get ofp device info rpc |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 167 | func (ap *AdapterProxy) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 168 | log.Debugw("GetOfpDeviceInfo", log.Fields{"deviceId": device.Id}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 169 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 170 | args := make([]*kafka.KVArg, 1) |
| 171 | args[0] = &kafka.KVArg{ |
| 172 | Key: "device", |
| 173 | Value: device, |
| 174 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 175 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 176 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 177 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, "get_ofp_device_info", &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 178 | log.Debugw("GetOfpDeviceInfo-response", log.Fields{"deviceId": device.Id, "success": success, "result": result}) |
| 179 | if success { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 180 | unpackResult := &ic.SwitchCapability{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 181 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 182 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 183 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 184 | } |
| 185 | return unpackResult, nil |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 186 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 187 | unpackResult := &ic.Error{} |
| 188 | var err error |
| 189 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 190 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 191 | } |
| 192 | log.Debugw("GetOfpDeviceInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 193 | // TODO: Need to get the real error code |
| 194 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 195 | } |
| 196 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 197 | // GetOfpPortInfo invokes get ofp port info rpc |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 198 | func (ap *AdapterProxy) GetOfpPortInfo(ctx context.Context, device *voltha.Device, portNo uint32) (*ic.PortCapability, error) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 199 | log.Debugw("GetOfpPortInfo", log.Fields{"deviceId": device.Id}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 200 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 201 | args := make([]*kafka.KVArg, 2) |
| 202 | args[0] = &kafka.KVArg{ |
| 203 | Key: "device", |
| 204 | Value: device, |
| 205 | } |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 206 | pNo := &ic.IntType{Val: int64(portNo)} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 207 | args[1] = &kafka.KVArg{ |
| 208 | Key: "port_no", |
| 209 | Value: pNo, |
| 210 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 211 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 212 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 213 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, "get_ofp_port_info", &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 214 | log.Debugw("GetOfpPortInfo-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 215 | if success { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 216 | unpackResult := &ic.PortCapability{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 217 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 218 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 219 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 220 | } |
| 221 | return unpackResult, nil |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 222 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 223 | unpackResult := &ic.Error{} |
| 224 | var err error |
| 225 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 226 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 227 | } |
| 228 | log.Debugw("GetOfpPortInfo-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 229 | // TODO: Need to get the real error code |
| 230 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | //TODO: Implement the functions below |
| 234 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 235 | // AdapterDescriptor - TODO |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 236 | func (ap *AdapterProxy) AdapterDescriptor() (*voltha.Adapter, error) { |
| 237 | log.Debug("AdapterDescriptor") |
| 238 | return nil, nil |
| 239 | } |
| 240 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 241 | // DeviceTypes - TODO |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 242 | func (ap *AdapterProxy) DeviceTypes() (*voltha.DeviceType, error) { |
| 243 | log.Debug("DeviceTypes") |
| 244 | return nil, nil |
| 245 | } |
| 246 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 247 | // Health - TODO |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 248 | func (ap *AdapterProxy) Health() (*voltha.HealthStatus, error) { |
| 249 | log.Debug("Health") |
| 250 | return nil, nil |
| 251 | } |
| 252 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 253 | // ReconcileDevice invokes reconcile device rpc |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 254 | func (ap *AdapterProxy) ReconcileDevice(ctx context.Context, device *voltha.Device) error { |
| 255 | log.Debugw("ReconcileDevice", log.Fields{"deviceId": device.Id}) |
Matt Jeanneret | 7cf8e0b | 2020-01-09 11:57:51 -0500 | [diff] [blame] | 256 | rpc := "reconcile_device" |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 257 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 258 | args := []*kafka.KVArg{ |
| 259 | {Key: "device", Value: device}, |
| 260 | } |
| 261 | // Use a device specific topic as we are the only core handling requests for this device |
| 262 | replyToTopic := ap.getCoreTopic() |
| 263 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
| 264 | log.Debugw("ReconcileDevice-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 265 | |
| 266 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 267 | } |
| 268 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 269 | // AbandonDevice - TODO |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 270 | func (ap *AdapterProxy) AbandonDevice(device voltha.Device) error { |
| 271 | log.Debug("AbandonDevice") |
| 272 | return nil |
| 273 | } |
| 274 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 275 | // GetDeviceDetails - TODO |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 276 | func (ap *AdapterProxy) GetDeviceDetails(device voltha.Device) (*voltha.Device, error) { |
| 277 | log.Debug("GetDeviceDetails") |
| 278 | return nil, nil |
| 279 | } |
| 280 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 281 | // DownloadImage invokes download image rpc |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 282 | func (ap *AdapterProxy) DownloadImage(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 283 | log.Debugw("DownloadImage", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 284 | rpc := "download_image" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 285 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 286 | args := make([]*kafka.KVArg, 2) |
| 287 | args[0] = &kafka.KVArg{ |
| 288 | Key: "device", |
| 289 | Value: device, |
| 290 | } |
| 291 | args[1] = &kafka.KVArg{ |
| 292 | Key: "request", |
| 293 | Value: download, |
| 294 | } |
| 295 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 296 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 297 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 298 | log.Debugw("DownloadImage-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 299 | |
| 300 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 301 | } |
| 302 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 303 | // GetImageDownloadStatus invokes get image download status rpc |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 304 | func (ap *AdapterProxy) GetImageDownloadStatus(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 305 | log.Debugw("GetImageDownloadStatus", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 306 | rpc := "get_image_download_status" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 307 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 308 | args := make([]*kafka.KVArg, 2) |
| 309 | args[0] = &kafka.KVArg{ |
| 310 | Key: "device", |
| 311 | Value: device, |
| 312 | } |
| 313 | args[1] = &kafka.KVArg{ |
| 314 | Key: "request", |
| 315 | Value: download, |
| 316 | } |
| 317 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 318 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 319 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 320 | log.Debugw("GetImageDownloadStatus-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 321 | |
| 322 | if success { |
| 323 | unpackResult := &voltha.ImageDownload{} |
| 324 | if err := ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 325 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 326 | return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error()) |
| 327 | } |
| 328 | return unpackResult, nil |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 329 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 330 | unpackResult := &ic.Error{} |
| 331 | var err error |
| 332 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 333 | log.Warnw("cannot-unmarshal-response", log.Fields{"error": err}) |
| 334 | return nil, err |
| 335 | } |
| 336 | log.Debugw("GetImageDownloadStatus-return", log.Fields{"deviceid": device.Id, "success": success, "error": err}) |
| 337 | return nil, status.Errorf(codes.Internal, "%s", unpackResult.Reason) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 338 | } |
| 339 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 340 | // CancelImageDownload invokes cancel image download rpc |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 341 | func (ap *AdapterProxy) CancelImageDownload(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 342 | log.Debugw("CancelImageDownload", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 343 | rpc := "cancel_image_download" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 344 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 345 | args := make([]*kafka.KVArg, 2) |
| 346 | args[0] = &kafka.KVArg{ |
| 347 | Key: "device", |
| 348 | Value: device, |
| 349 | } |
| 350 | args[1] = &kafka.KVArg{ |
| 351 | Key: "request", |
| 352 | Value: download, |
| 353 | } |
| 354 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 355 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 356 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 357 | log.Debugw("CancelImageDownload-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 358 | |
| 359 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 360 | } |
| 361 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 362 | // ActivateImageUpdate invokes activate image update rpc |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 363 | func (ap *AdapterProxy) ActivateImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 364 | log.Debugw("ActivateImageUpdate", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 365 | rpc := "activate_image_update" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 366 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 367 | args := make([]*kafka.KVArg, 2) |
| 368 | args[0] = &kafka.KVArg{ |
| 369 | Key: "device", |
| 370 | Value: device, |
| 371 | } |
| 372 | args[1] = &kafka.KVArg{ |
| 373 | Key: "request", |
| 374 | Value: download, |
| 375 | } |
| 376 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 377 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 378 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 379 | log.Debugw("ActivateImageUpdate-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 380 | |
| 381 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 382 | } |
| 383 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 384 | // RevertImageUpdate invokes revert image update rpc |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 385 | func (ap *AdapterProxy) RevertImageUpdate(ctx context.Context, device *voltha.Device, download *voltha.ImageDownload) error { |
| 386 | log.Debugw("RevertImageUpdate", log.Fields{"deviceId": device.Id, "image": download.Name}) |
| 387 | rpc := "revert_image_update" |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 388 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 389 | args := make([]*kafka.KVArg, 2) |
| 390 | args[0] = &kafka.KVArg{ |
| 391 | Key: "device", |
| 392 | Value: device, |
| 393 | } |
| 394 | args[1] = &kafka.KVArg{ |
| 395 | Key: "request", |
| 396 | Value: download, |
| 397 | } |
| 398 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 399 | replyToTopic := ap.getCoreTopic() |
khenaidoo | bdcb8e0 | 2019-03-06 16:28:56 -0500 | [diff] [blame] | 400 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 401 | log.Debugw("RevertImageUpdate-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 402 | |
| 403 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 404 | } |
| 405 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 406 | // SelfTestDevice - TODO |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 407 | func (ap *AdapterProxy) SelfTestDevice(device voltha.Device) (*voltha.SelfTestResponse, error) { |
| 408 | log.Debug("SelfTestDevice") |
| 409 | return nil, nil |
| 410 | } |
| 411 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 412 | func (ap *AdapterProxy) packetOut(ctx context.Context, deviceType string, deviceID string, outPort uint32, packet *openflow_13.OfpPacketOut) error { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 413 | log.Debugw("packetOut", log.Fields{"deviceId": deviceID}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 414 | toTopic := ap.getAdapterTopic(deviceType) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 415 | rpc := "receive_packet_out" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 416 | dID := &ic.StrType{Val: deviceID} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 417 | args := make([]*kafka.KVArg, 3) |
| 418 | args[0] = &kafka.KVArg{ |
| 419 | Key: "deviceId", |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 420 | Value: dID, |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 421 | } |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 422 | op := &ic.IntType{Val: int64(outPort)} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 423 | args[1] = &kafka.KVArg{ |
| 424 | Key: "outPort", |
| 425 | Value: op, |
| 426 | } |
| 427 | args[2] = &kafka.KVArg{ |
| 428 | Key: "packet", |
| 429 | Value: packet, |
| 430 | } |
| 431 | |
| 432 | // TODO: Do we need to wait for an ACK on a packet Out? |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 433 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 434 | replyToTopic := ap.getCoreTopic() |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 435 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, deviceID, args...) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 436 | log.Debugw("packetOut", log.Fields{"deviceid": deviceID, "success": success}) |
| 437 | return unPackResponse(rpc, deviceID, success, result) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 438 | } |
| 439 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 440 | // UpdateFlowsBulk invokes update flows bulk rpc |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 441 | func (ap *AdapterProxy) UpdateFlowsBulk(ctx context.Context, device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 442 | log.Debugw("UpdateFlowsBulk", log.Fields{"deviceId": device.Id, "flowsInUpdate": len(flows.Items), "groupsToUpdate": len(groups.Items)}) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 443 | toTopic := ap.getAdapterTopic(device.Adapter) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 444 | rpc := "update_flows_bulk" |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 445 | args := make([]*kafka.KVArg, 4) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 446 | args[0] = &kafka.KVArg{ |
| 447 | Key: "device", |
| 448 | Value: device, |
| 449 | } |
| 450 | args[1] = &kafka.KVArg{ |
| 451 | Key: "flows", |
| 452 | Value: flows, |
| 453 | } |
| 454 | args[2] = &kafka.KVArg{ |
| 455 | Key: "groups", |
| 456 | Value: groups, |
| 457 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 458 | args[3] = &kafka.KVArg{ |
| 459 | Key: "flow_metadata", |
| 460 | Value: flowMetadata, |
| 461 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 462 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 463 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 464 | replyToTopic := ap.getCoreTopic() |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 465 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 466 | log.Debugw("UpdateFlowsBulk-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 467 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 468 | } |
| 469 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 470 | // UpdateFlowsIncremental invokes update flows incremental rpc |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 471 | func (ap *AdapterProxy) UpdateFlowsIncremental(ctx context.Context, device *voltha.Device, flowChanges *openflow_13.FlowChanges, groupChanges *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { |
khenaidoo | 0458db6 | 2019-06-20 08:50:36 -0400 | [diff] [blame] | 472 | log.Debugw("UpdateFlowsIncremental", |
| 473 | log.Fields{ |
| 474 | "deviceId": device.Id, |
| 475 | "flowsToAdd": len(flowChanges.ToAdd.Items), |
| 476 | "flowsToDelete": len(flowChanges.ToRemove.Items), |
| 477 | "groupsToAdd": len(groupChanges.ToAdd.Items), |
| 478 | "groupsToDelete": len(groupChanges.ToRemove.Items), |
| 479 | "groupsToUpdate": len(groupChanges.ToUpdate.Items), |
| 480 | }) |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 481 | toTopic := ap.getAdapterTopic(device.Adapter) |
Matt Jeanneret | b003742 | 2019-03-23 14:36:51 -0400 | [diff] [blame] | 482 | rpc := "update_flows_incrementally" |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 483 | args := make([]*kafka.KVArg, 4) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 484 | args[0] = &kafka.KVArg{ |
| 485 | Key: "device", |
| 486 | Value: device, |
| 487 | } |
| 488 | args[1] = &kafka.KVArg{ |
| 489 | Key: "flow_changes", |
| 490 | Value: flowChanges, |
| 491 | } |
| 492 | args[2] = &kafka.KVArg{ |
| 493 | Key: "group_changes", |
| 494 | Value: groupChanges, |
| 495 | } |
| 496 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 497 | args[3] = &kafka.KVArg{ |
| 498 | Key: "flow_metadata", |
| 499 | Value: flowMetadata, |
| 500 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 501 | // Use a device specific topic as we are the only core handling requests for this device |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 502 | replyToTopic := ap.getCoreTopic() |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 503 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 504 | log.Debugw("UpdateFlowsIncremental-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 505 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 506 | } |
| 507 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 508 | // UpdatePmConfigs invokes update pm configs rpc |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 509 | func (ap *AdapterProxy) UpdatePmConfigs(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error { |
| 510 | log.Debugw("UpdatePmConfigs", log.Fields{"deviceId": device.Id}) |
| 511 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 512 | rpc := "Update_pm_config" |
| 513 | args := make([]*kafka.KVArg, 2) |
| 514 | args[0] = &kafka.KVArg{ |
| 515 | Key: "device", |
| 516 | Value: device, |
| 517 | } |
| 518 | args[1] = &kafka.KVArg{ |
| 519 | Key: "pm_configs", |
| 520 | Value: pmConfigs, |
| 521 | } |
| 522 | |
| 523 | replyToTopic := ap.getCoreTopic() |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 524 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 525 | log.Debugw("UpdatePmConfigs-response", log.Fields{"deviceid": device.Id, "success": success}) |
| 526 | return unPackResponse(rpc, device.Id, success, result) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 527 | } |
| 528 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 529 | // ReceivePacketOut - TODO |
| 530 | func (ap *AdapterProxy) ReceivePacketOut(deviceID voltha.ID, egressPortNo int, msg interface{}) error { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 531 | log.Debug("ReceivePacketOut") |
| 532 | return nil |
| 533 | } |
| 534 | |
Devmalya Paul | c594bb3 | 2019-11-06 07:34:27 +0000 | [diff] [blame] | 535 | func (ap *AdapterProxy) SuppressEvent(filter *voltha.EventFilter) error { |
| 536 | log.Debug("SuppressEvent") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 537 | return nil |
| 538 | } |
| 539 | |
Devmalya Paul | c594bb3 | 2019-11-06 07:34:27 +0000 | [diff] [blame] | 540 | func (ap *AdapterProxy) UnSuppressEvent(filter *voltha.EventFilter) error { |
| 541 | log.Debug("UnSuppressEvent") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 542 | return nil |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 543 | } |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 544 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 545 | // SimulateAlarm invokes simulate alarm rpc |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 546 | func (ap *AdapterProxy) SimulateAlarm(ctx context.Context, device *voltha.Device, simulatereq *voltha.SimulateAlarmRequest) error { |
| 547 | log.Debugw("SimulateAlarm", log.Fields{"id": simulatereq.Id}) |
| 548 | rpc := "simulate_alarm" |
| 549 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 550 | args := make([]*kafka.KVArg, 2) |
| 551 | args[0] = &kafka.KVArg{ |
| 552 | Key: "device", |
| 553 | Value: device, |
| 554 | } |
| 555 | args[1] = &kafka.KVArg{ |
| 556 | Key: "request", |
| 557 | Value: simulatereq, |
| 558 | } |
| 559 | |
| 560 | // Use a device topic for the response as we are the only core handling requests for this device |
| 561 | replyToTopic := ap.getCoreTopic() |
| 562 | ap.deviceTopicRegistered = true |
| 563 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
| 564 | log.Debugw("SimulateAlarm-response", log.Fields{"replyTopic": replyToTopic, "deviceid": device.Id, "success": success}) |
| 565 | return unPackResponse(rpc, device.Id, success, result) |
| 566 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 567 | |
| 568 | func (ap *AdapterProxy) disablePort(ctx context.Context, device *voltha.Device, port *voltha.Port) error { |
| 569 | log.Debugw("disablePort", log.Fields{"device-id": device.Id, "port-no": port.PortNo}) |
| 570 | rpc := "disable_port" |
| 571 | deviceID := &ic.StrType{Val: device.Id} |
| 572 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 573 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 574 | // specific topic |
| 575 | args := make([]*kafka.KVArg, 2) |
| 576 | args[0] = &kafka.KVArg{ |
| 577 | Key: "deviceId", |
| 578 | Value: deviceID, |
| 579 | } |
| 580 | |
| 581 | args[1] = &kafka.KVArg{ |
| 582 | Key: "port", |
| 583 | Value: port, |
| 584 | } |
| 585 | |
| 586 | replyToTopic := ap.getCoreTopic() |
| 587 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
| 588 | log.Debugw("disablePort-response", log.Fields{"device-id": device.Id, "port-no": port.PortNo, "success": success}) |
| 589 | return unPackResponse(rpc, device.Id, success, result) |
| 590 | } |
| 591 | |
| 592 | func (ap *AdapterProxy) enablePort(ctx context.Context, device *voltha.Device, port *voltha.Port) error { |
| 593 | log.Debugw("enablePort", log.Fields{"device-id": device.Id, "port-no": port.PortNo}) |
| 594 | rpc := "enable_port" |
| 595 | deviceID := &ic.StrType{Val: device.Id} |
| 596 | toTopic := ap.getAdapterTopic(device.Adapter) |
| 597 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 598 | // specific topic |
| 599 | args := make([]*kafka.KVArg, 2) |
| 600 | args[0] = &kafka.KVArg{ |
| 601 | Key: "deviceId", |
| 602 | Value: deviceID, |
| 603 | } |
| 604 | |
| 605 | args[1] = &kafka.KVArg{ |
| 606 | Key: "port", |
| 607 | Value: port, |
| 608 | } |
| 609 | |
| 610 | replyToTopic := ap.getCoreTopic() |
| 611 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
| 612 | log.Debugw("enablePort-response", log.Fields{"device-id": device.Id, "port-no": port.PortNo, "success": success}) |
| 613 | return unPackResponse(rpc, device.Id, success, result) |
| 614 | } |