Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [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 | */ |
| 16 | package common |
| 17 | |
| 18 | import ( |
| 19 | "context" |
Chaitrashree G S | 66d4135 | 2020-01-09 20:18:58 -0500 | [diff] [blame] | 20 | "sync" |
| 21 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 22 | "github.com/golang/protobuf/ptypes" |
| 23 | a "github.com/golang/protobuf/ptypes/any" |
serkant.uluderya | b38671c | 2019-11-01 09:35:38 -0700 | [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/voltha" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 28 | "google.golang.org/grpc/codes" |
| 29 | "google.golang.org/grpc/status" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 30 | ) |
| 31 | |
| 32 | type CoreProxy struct { |
Matteo Scandolo | 2ba00d3 | 2020-01-16 17:33:03 -0800 | [diff] [blame] | 33 | kafkaICProxy kafka.InterContainerProxy |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 34 | adapterTopic string |
| 35 | coreTopic string |
| 36 | deviceIdCoreMap map[string]string |
| 37 | lockDeviceIdCoreMap sync.RWMutex |
| 38 | } |
| 39 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 40 | func NewCoreProxy(ctx context.Context, kafkaProxy kafka.InterContainerProxy, adapterTopic string, coreTopic string) *CoreProxy { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 41 | var proxy CoreProxy |
| 42 | proxy.kafkaICProxy = kafkaProxy |
| 43 | proxy.adapterTopic = adapterTopic |
| 44 | proxy.coreTopic = coreTopic |
| 45 | proxy.deviceIdCoreMap = make(map[string]string) |
| 46 | proxy.lockDeviceIdCoreMap = sync.RWMutex{} |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 47 | logger.Debugw(ctx, "TOPICS", log.Fields{"core": proxy.coreTopic, "adapter": proxy.adapterTopic}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 48 | |
| 49 | return &proxy |
| 50 | } |
| 51 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 52 | func unPackResponse(ctx context.Context, rpc string, deviceId string, success bool, response *a.Any) error { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 53 | if success { |
| 54 | return nil |
| 55 | } else { |
| 56 | unpackResult := &ic.Error{} |
| 57 | var err error |
| 58 | if err = ptypes.UnmarshalAny(response, unpackResult); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 59 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 60 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 61 | logger.Debugw(ctx, "response", log.Fields{"rpc": rpc, "deviceId": deviceId, "success": success, "error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 62 | // TODO: Need to get the real error code |
| 63 | return status.Errorf(codes.Canceled, "%s", unpackResult.Reason) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // UpdateCoreReference adds or update a core reference (really the topic name) for a given device Id |
| 68 | func (ap *CoreProxy) UpdateCoreReference(deviceId string, coreReference string) { |
| 69 | ap.lockDeviceIdCoreMap.Lock() |
| 70 | defer ap.lockDeviceIdCoreMap.Unlock() |
| 71 | ap.deviceIdCoreMap[deviceId] = coreReference |
| 72 | } |
| 73 | |
| 74 | // DeleteCoreReference removes a core reference (really the topic name) for a given device Id |
| 75 | func (ap *CoreProxy) DeleteCoreReference(deviceId string) { |
| 76 | ap.lockDeviceIdCoreMap.Lock() |
| 77 | defer ap.lockDeviceIdCoreMap.Unlock() |
| 78 | delete(ap.deviceIdCoreMap, deviceId) |
| 79 | } |
| 80 | |
| 81 | func (ap *CoreProxy) getCoreTopic(deviceId string) kafka.Topic { |
| 82 | ap.lockDeviceIdCoreMap.Lock() |
| 83 | defer ap.lockDeviceIdCoreMap.Unlock() |
| 84 | |
| 85 | if t, exist := ap.deviceIdCoreMap[deviceId]; exist { |
| 86 | return kafka.Topic{Name: t} |
| 87 | } |
| 88 | |
| 89 | return kafka.Topic{Name: ap.coreTopic} |
| 90 | } |
| 91 | |
| 92 | func (ap *CoreProxy) getAdapterTopic(args ...string) kafka.Topic { |
| 93 | return kafka.Topic{Name: ap.adapterTopic} |
| 94 | } |
| 95 | |
| 96 | func (ap *CoreProxy) RegisterAdapter(ctx context.Context, adapter *voltha.Adapter, deviceTypes *voltha.DeviceTypes) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 97 | logger.Debugw(ctx, "registering-adapter", log.Fields{"coreTopic": ap.coreTopic, "adapterTopic": ap.adapterTopic}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 98 | rpc := "Register" |
| 99 | topic := kafka.Topic{Name: ap.coreTopic} |
| 100 | replyToTopic := ap.getAdapterTopic() |
| 101 | args := make([]*kafka.KVArg, 2) |
Matteo Scandolo | d58eaef | 2020-03-30 12:30:02 -0700 | [diff] [blame] | 102 | |
| 103 | if adapter.TotalReplicas == 0 && adapter.CurrentReplica != 0 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 104 | logger.Fatal(ctx, "totalReplicas can't be 0, since you're here you have at least one") |
Matteo Scandolo | d58eaef | 2020-03-30 12:30:02 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | if adapter.CurrentReplica == 0 && adapter.TotalReplicas != 0 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 108 | logger.Fatal(ctx, "currentReplica can't be 0, it has to start from 1") |
Matteo Scandolo | d58eaef | 2020-03-30 12:30:02 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | if adapter.CurrentReplica == 0 && adapter.TotalReplicas == 0 { |
| 112 | // if the adapter is not setting these fields they default to 0, |
| 113 | // in that case it means the adapter is not ready to be scaled and thus it defaults |
| 114 | // to a single instance |
| 115 | adapter.CurrentReplica = 1 |
| 116 | adapter.TotalReplicas = 1 |
| 117 | } |
| 118 | |
| 119 | if adapter.CurrentReplica > adapter.TotalReplicas { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 120 | logger.Fatalf(ctx, "CurrentReplica (%d) can't be greater than TotalReplicas (%d)", |
Matteo Scandolo | d58eaef | 2020-03-30 12:30:02 -0700 | [diff] [blame] | 121 | adapter.CurrentReplica, adapter.TotalReplicas) |
| 122 | } |
| 123 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 124 | args[0] = &kafka.KVArg{ |
| 125 | Key: "adapter", |
| 126 | Value: adapter, |
| 127 | } |
| 128 | args[1] = &kafka.KVArg{ |
| 129 | Key: "deviceTypes", |
| 130 | Value: deviceTypes, |
| 131 | } |
| 132 | |
| 133 | success, result := ap.kafkaICProxy.InvokeRPC(ctx, rpc, &topic, &replyToTopic, true, "", args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 134 | logger.Debugw(ctx, "Register-Adapter-response", log.Fields{"replyTopic": replyToTopic, "success": success}) |
| 135 | return unPackResponse(ctx, rpc, "", success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | func (ap *CoreProxy) DeviceUpdate(ctx context.Context, device *voltha.Device) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 139 | logger.Debugw(ctx, "DeviceUpdate", log.Fields{"deviceId": device.Id}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 140 | rpc := "DeviceUpdate" |
| 141 | toTopic := ap.getCoreTopic(device.Id) |
| 142 | args := make([]*kafka.KVArg, 1) |
| 143 | args[0] = &kafka.KVArg{ |
| 144 | Key: "device", |
| 145 | Value: device, |
| 146 | } |
| 147 | // Use a device specific topic as we are the only adaptercore handling requests for this device |
| 148 | replyToTopic := ap.getAdapterTopic() |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 149 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, device.Id, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 150 | logger.Debugw(ctx, "DeviceUpdate-response", log.Fields{"deviceId": device.Id, "success": success}) |
| 151 | return unPackResponse(ctx, rpc, device.Id, success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | func (ap *CoreProxy) PortCreated(ctx context.Context, deviceId string, port *voltha.Port) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 155 | logger.Debugw(ctx, "PortCreated", log.Fields{"portNo": port.PortNo}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 156 | rpc := "PortCreated" |
| 157 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 158 | // specific topic |
| 159 | toTopic := ap.getCoreTopic(deviceId) |
| 160 | args := make([]*kafka.KVArg, 2) |
| 161 | id := &voltha.ID{Id: deviceId} |
| 162 | args[0] = &kafka.KVArg{ |
| 163 | Key: "device_id", |
| 164 | Value: id, |
| 165 | } |
| 166 | args[1] = &kafka.KVArg{ |
| 167 | Key: "port", |
| 168 | Value: port, |
| 169 | } |
| 170 | |
| 171 | // Use a device specific topic as we are the only adaptercore handling requests for this device |
| 172 | replyToTopic := ap.getAdapterTopic() |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 173 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 174 | logger.Debugw(ctx, "PortCreated-response", log.Fields{"deviceId": deviceId, "success": success}) |
| 175 | return unPackResponse(ctx, rpc, deviceId, success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Kent Hagerman | 143fea3 | 2020-07-10 15:28:55 -0400 | [diff] [blame] | 178 | func (ap *CoreProxy) PortsStateUpdate(ctx context.Context, deviceId string, portTypeFilter uint32, operStatus voltha.OperStatus_Types) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 179 | logger.Debugw(ctx, "PortsStateUpdate", log.Fields{"deviceId": deviceId}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 180 | rpc := "PortsStateUpdate" |
| 181 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 182 | // specific topic |
| 183 | toTopic := ap.getCoreTopic(deviceId) |
Kent Hagerman | 143fea3 | 2020-07-10 15:28:55 -0400 | [diff] [blame] | 184 | args := []*kafka.KVArg{{ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 185 | Key: "device_id", |
Kent Hagerman | 143fea3 | 2020-07-10 15:28:55 -0400 | [diff] [blame] | 186 | Value: &voltha.ID{Id: deviceId}, |
| 187 | }, { |
| 188 | Key: "port_type_filter", |
| 189 | Value: &ic.IntType{Val: int64(portTypeFilter)}, |
| 190 | }, { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 191 | Key: "oper_status", |
Kent Hagerman | 143fea3 | 2020-07-10 15:28:55 -0400 | [diff] [blame] | 192 | Value: &ic.IntType{Val: int64(operStatus)}, |
| 193 | }} |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 194 | |
| 195 | // Use a device specific topic as we are the only adaptercore handling requests for this device |
| 196 | replyToTopic := ap.getAdapterTopic() |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 197 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 198 | logger.Debugw(ctx, "PortsStateUpdate-response", log.Fields{"deviceId": deviceId, "success": success}) |
| 199 | return unPackResponse(ctx, rpc, deviceId, success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | func (ap *CoreProxy) DeleteAllPorts(ctx context.Context, deviceId string) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 203 | logger.Debugw(ctx, "DeleteAllPorts", log.Fields{"deviceId": deviceId}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 204 | rpc := "DeleteAllPorts" |
| 205 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 206 | // specific topic |
| 207 | toTopic := ap.getCoreTopic(deviceId) |
| 208 | args := make([]*kafka.KVArg, 2) |
| 209 | id := &voltha.ID{Id: deviceId} |
| 210 | |
| 211 | args[0] = &kafka.KVArg{ |
| 212 | Key: "device_id", |
| 213 | Value: id, |
| 214 | } |
| 215 | |
| 216 | // Use a device specific topic as we are the only adaptercore handling requests for this device |
| 217 | replyToTopic := ap.getAdapterTopic() |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 218 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 219 | logger.Debugw(ctx, "DeleteAllPorts-response", log.Fields{"deviceId": deviceId, "success": success}) |
| 220 | return unPackResponse(ctx, rpc, deviceId, success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Kent Hagerman | 143fea3 | 2020-07-10 15:28:55 -0400 | [diff] [blame] | 223 | func (ap *CoreProxy) GetDevicePort(ctx context.Context, deviceID string, portNo uint32) (*voltha.Port, error) { |
| 224 | logger.Debugw(ctx, "GetDevicePort", log.Fields{"device-id": deviceID}) |
| 225 | rpc := "GetDevicePort" |
| 226 | |
| 227 | toTopic := ap.getCoreTopic(deviceID) |
| 228 | replyToTopic := ap.getAdapterTopic() |
| 229 | |
| 230 | args := []*kafka.KVArg{{ |
| 231 | Key: "device_id", |
| 232 | Value: &voltha.ID{Id: deviceID}, |
| 233 | }, { |
| 234 | Key: "port_no", |
| 235 | Value: &ic.IntType{Val: int64(portNo)}, |
| 236 | }} |
| 237 | |
| 238 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceID, args...) |
| 239 | logger.Debugw(ctx, "GetDevicePort-response", log.Fields{"device-id": deviceID, "success": success}) |
| 240 | |
| 241 | if success { |
| 242 | port := &voltha.Port{} |
| 243 | if err := ptypes.UnmarshalAny(result, port); err != nil { |
| 244 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
| 245 | return nil, status.Error(codes.InvalidArgument, err.Error()) |
| 246 | } |
| 247 | return port, nil |
| 248 | } else { |
| 249 | unpackResult := &ic.Error{} |
| 250 | var err error |
| 251 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 252 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
| 253 | } |
| 254 | logger.Debugw(ctx, "GetDevicePort-return", log.Fields{"device-id": deviceID, "success": success, "error": err}) |
| 255 | // TODO: Need to get the real error code |
| 256 | return nil, status.Error(ICProxyErrorCodeToGrpcErrorCode(ctx, unpackResult.Code), unpackResult.Reason) |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | func (ap *CoreProxy) ListDevicePorts(ctx context.Context, deviceID string) ([]*voltha.Port, error) { |
| 261 | logger.Debugw(ctx, "ListDevicePorts", log.Fields{"device-id": deviceID}) |
| 262 | rpc := "ListDevicePorts" |
| 263 | |
| 264 | toTopic := ap.getCoreTopic(deviceID) |
| 265 | replyToTopic := ap.getAdapterTopic() |
| 266 | |
| 267 | args := []*kafka.KVArg{{ |
| 268 | Key: "device_id", |
| 269 | Value: &voltha.ID{Id: deviceID}, |
| 270 | }} |
| 271 | |
| 272 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceID, args...) |
| 273 | logger.Debugw(ctx, "ListDevicePorts-response", log.Fields{"device-id": deviceID, "success": success}) |
| 274 | |
| 275 | if success { |
| 276 | ports := &voltha.Ports{} |
| 277 | if err := ptypes.UnmarshalAny(result, ports); err != nil { |
| 278 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
| 279 | return nil, status.Error(codes.InvalidArgument, err.Error()) |
| 280 | } |
| 281 | return ports.Items, nil |
| 282 | } else { |
| 283 | unpackResult := &ic.Error{} |
| 284 | var err error |
| 285 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
| 286 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
| 287 | } |
| 288 | logger.Debugw(ctx, "ListDevicePorts-return", log.Fields{"device-id": deviceID, "success": success, "error": err}) |
| 289 | // TODO: Need to get the real error code |
| 290 | return nil, status.Error(ICProxyErrorCodeToGrpcErrorCode(ctx, unpackResult.Code), unpackResult.Reason) |
| 291 | } |
| 292 | } |
| 293 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 294 | func (ap *CoreProxy) DeviceStateUpdate(ctx context.Context, deviceId string, |
serkant.uluderya | b38671c | 2019-11-01 09:35:38 -0700 | [diff] [blame] | 295 | connStatus voltha.ConnectStatus_Types, operStatus voltha.OperStatus_Types) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 296 | logger.Debugw(ctx, "DeviceStateUpdate", log.Fields{"deviceId": deviceId}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 297 | rpc := "DeviceStateUpdate" |
| 298 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 299 | // specific topic |
| 300 | toTopic := ap.getCoreTopic(deviceId) |
| 301 | args := make([]*kafka.KVArg, 3) |
| 302 | id := &voltha.ID{Id: deviceId} |
| 303 | oStatus := &ic.IntType{Val: int64(operStatus)} |
| 304 | cStatus := &ic.IntType{Val: int64(connStatus)} |
| 305 | |
| 306 | args[0] = &kafka.KVArg{ |
| 307 | Key: "device_id", |
| 308 | Value: id, |
| 309 | } |
| 310 | args[1] = &kafka.KVArg{ |
| 311 | Key: "oper_status", |
| 312 | Value: oStatus, |
| 313 | } |
| 314 | args[2] = &kafka.KVArg{ |
| 315 | Key: "connect_status", |
| 316 | Value: cStatus, |
| 317 | } |
| 318 | // Use a device specific topic as we are the only adaptercore handling requests for this device |
| 319 | replyToTopic := ap.getAdapterTopic() |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 320 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 321 | logger.Debugw(ctx, "DeviceStateUpdate-response", log.Fields{"deviceId": deviceId, "success": success}) |
| 322 | return unPackResponse(ctx, rpc, deviceId, success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | func (ap *CoreProxy) ChildDeviceDetected(ctx context.Context, parentDeviceId string, parentPortNo int, |
| 326 | childDeviceType string, channelId int, vendorId string, serialNumber string, onuId int64) (*voltha.Device, error) { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 327 | logger.Debugw(ctx, "ChildDeviceDetected", log.Fields{"pDeviceId": parentDeviceId, "channelId": channelId}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 328 | rpc := "ChildDeviceDetected" |
| 329 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 330 | // specific topic |
| 331 | toTopic := ap.getCoreTopic(parentDeviceId) |
| 332 | replyToTopic := ap.getAdapterTopic() |
| 333 | |
| 334 | args := make([]*kafka.KVArg, 7) |
| 335 | id := &voltha.ID{Id: parentDeviceId} |
| 336 | args[0] = &kafka.KVArg{ |
| 337 | Key: "parent_device_id", |
| 338 | Value: id, |
| 339 | } |
| 340 | ppn := &ic.IntType{Val: int64(parentPortNo)} |
| 341 | args[1] = &kafka.KVArg{ |
| 342 | Key: "parent_port_no", |
| 343 | Value: ppn, |
| 344 | } |
| 345 | cdt := &ic.StrType{Val: childDeviceType} |
| 346 | args[2] = &kafka.KVArg{ |
| 347 | Key: "child_device_type", |
| 348 | Value: cdt, |
| 349 | } |
| 350 | channel := &ic.IntType{Val: int64(channelId)} |
| 351 | args[3] = &kafka.KVArg{ |
| 352 | Key: "channel_id", |
| 353 | Value: channel, |
| 354 | } |
| 355 | vId := &ic.StrType{Val: vendorId} |
| 356 | args[4] = &kafka.KVArg{ |
| 357 | Key: "vendor_id", |
| 358 | Value: vId, |
| 359 | } |
| 360 | sNo := &ic.StrType{Val: serialNumber} |
| 361 | args[5] = &kafka.KVArg{ |
| 362 | Key: "serial_number", |
| 363 | Value: sNo, |
| 364 | } |
| 365 | oId := &ic.IntType{Val: int64(onuId)} |
| 366 | args[6] = &kafka.KVArg{ |
| 367 | Key: "onu_id", |
| 368 | Value: oId, |
| 369 | } |
| 370 | |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 371 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 372 | logger.Debugw(ctx, "ChildDeviceDetected-response", log.Fields{"pDeviceId": parentDeviceId, "success": success}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 373 | |
| 374 | if success { |
| 375 | volthaDevice := &voltha.Device{} |
| 376 | if err := ptypes.UnmarshalAny(result, volthaDevice); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 377 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
Matteo Scandolo | 1530d41 | 2020-01-30 14:57:46 -0800 | [diff] [blame] | 378 | return nil, status.Error(codes.InvalidArgument, err.Error()) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 379 | } |
| 380 | return volthaDevice, nil |
| 381 | } else { |
| 382 | unpackResult := &ic.Error{} |
| 383 | var err error |
| 384 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 385 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 386 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 387 | logger.Debugw(ctx, "ChildDeviceDetected-return", log.Fields{"deviceid": parentDeviceId, "success": success, "error": err}) |
Matteo Scandolo | 1530d41 | 2020-01-30 14:57:46 -0800 | [diff] [blame] | 388 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 389 | return nil, status.Error(ICProxyErrorCodeToGrpcErrorCode(ctx, unpackResult.Code), unpackResult.Reason) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | } |
| 393 | |
| 394 | func (ap *CoreProxy) ChildDevicesLost(ctx context.Context, parentDeviceId string) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 395 | logger.Debugw(ctx, "ChildDevicesLost", log.Fields{"pDeviceId": parentDeviceId}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 396 | rpc := "ChildDevicesLost" |
| 397 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 398 | // specific topic |
| 399 | toTopic := ap.getCoreTopic(parentDeviceId) |
| 400 | replyToTopic := ap.getAdapterTopic() |
| 401 | |
| 402 | args := make([]*kafka.KVArg, 1) |
| 403 | id := &voltha.ID{Id: parentDeviceId} |
| 404 | args[0] = &kafka.KVArg{ |
| 405 | Key: "parent_device_id", |
| 406 | Value: id, |
| 407 | } |
| 408 | |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 409 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 410 | logger.Debugw(ctx, "ChildDevicesLost-response", log.Fields{"pDeviceId": parentDeviceId, "success": success}) |
| 411 | return unPackResponse(ctx, rpc, parentDeviceId, success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | func (ap *CoreProxy) ChildDevicesDetected(ctx context.Context, parentDeviceId string) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 415 | logger.Debugw(ctx, "ChildDevicesDetected", log.Fields{"pDeviceId": parentDeviceId}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 416 | rpc := "ChildDevicesDetected" |
| 417 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 418 | // specific topic |
| 419 | toTopic := ap.getCoreTopic(parentDeviceId) |
| 420 | replyToTopic := ap.getAdapterTopic() |
| 421 | |
| 422 | args := make([]*kafka.KVArg, 1) |
| 423 | id := &voltha.ID{Id: parentDeviceId} |
| 424 | args[0] = &kafka.KVArg{ |
| 425 | Key: "parent_device_id", |
| 426 | Value: id, |
| 427 | } |
| 428 | |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 429 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 430 | logger.Debugw(ctx, "ChildDevicesDetected-response", log.Fields{"pDeviceId": parentDeviceId, "success": success}) |
| 431 | return unPackResponse(ctx, rpc, parentDeviceId, success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | func (ap *CoreProxy) GetDevice(ctx context.Context, parentDeviceId string, deviceId string) (*voltha.Device, error) { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 435 | logger.Debugw(ctx, "GetDevice", log.Fields{"deviceId": deviceId}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 436 | rpc := "GetDevice" |
| 437 | |
| 438 | toTopic := ap.getCoreTopic(parentDeviceId) |
| 439 | replyToTopic := ap.getAdapterTopic() |
| 440 | |
| 441 | args := make([]*kafka.KVArg, 1) |
| 442 | id := &voltha.ID{Id: deviceId} |
| 443 | args[0] = &kafka.KVArg{ |
| 444 | Key: "device_id", |
| 445 | Value: id, |
| 446 | } |
| 447 | |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 448 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 449 | logger.Debugw(ctx, "GetDevice-response", log.Fields{"pDeviceId": parentDeviceId, "success": success}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 450 | |
| 451 | if success { |
| 452 | volthaDevice := &voltha.Device{} |
| 453 | if err := ptypes.UnmarshalAny(result, volthaDevice); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 454 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
Matteo Scandolo | 1530d41 | 2020-01-30 14:57:46 -0800 | [diff] [blame] | 455 | return nil, status.Error(codes.InvalidArgument, err.Error()) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 456 | } |
| 457 | return volthaDevice, nil |
| 458 | } else { |
| 459 | unpackResult := &ic.Error{} |
| 460 | var err error |
| 461 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 462 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 463 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 464 | logger.Debugw(ctx, "GetDevice-return", log.Fields{"deviceid": parentDeviceId, "success": success, "error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 465 | // TODO: Need to get the real error code |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 466 | return nil, status.Error(ICProxyErrorCodeToGrpcErrorCode(ctx, unpackResult.Code), unpackResult.Reason) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
| 470 | func (ap *CoreProxy) GetChildDevice(ctx context.Context, parentDeviceId string, kwargs map[string]interface{}) (*voltha.Device, error) { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 471 | logger.Debugw(ctx, "GetChildDevice", log.Fields{"parentDeviceId": parentDeviceId, "kwargs": kwargs}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 472 | rpc := "GetChildDevice" |
| 473 | |
| 474 | toTopic := ap.getCoreTopic(parentDeviceId) |
| 475 | replyToTopic := ap.getAdapterTopic() |
| 476 | |
| 477 | args := make([]*kafka.KVArg, 4) |
| 478 | id := &voltha.ID{Id: parentDeviceId} |
| 479 | args[0] = &kafka.KVArg{ |
| 480 | Key: "device_id", |
| 481 | Value: id, |
| 482 | } |
| 483 | |
| 484 | var cnt uint8 = 0 |
| 485 | for k, v := range kwargs { |
| 486 | cnt += 1 |
| 487 | if k == "serial_number" { |
| 488 | val := &ic.StrType{Val: v.(string)} |
| 489 | args[cnt] = &kafka.KVArg{ |
| 490 | Key: k, |
| 491 | Value: val, |
| 492 | } |
| 493 | } else if k == "onu_id" { |
| 494 | val := &ic.IntType{Val: int64(v.(uint32))} |
| 495 | args[cnt] = &kafka.KVArg{ |
| 496 | Key: k, |
| 497 | Value: val, |
| 498 | } |
| 499 | } else if k == "parent_port_no" { |
| 500 | val := &ic.IntType{Val: int64(v.(uint32))} |
| 501 | args[cnt] = &kafka.KVArg{ |
| 502 | Key: k, |
| 503 | Value: val, |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 508 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 509 | logger.Debugw(ctx, "GetChildDevice-response", log.Fields{"pDeviceId": parentDeviceId, "success": success}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 510 | |
| 511 | if success { |
| 512 | volthaDevice := &voltha.Device{} |
| 513 | if err := ptypes.UnmarshalAny(result, volthaDevice); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 514 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
Matteo Scandolo | 1530d41 | 2020-01-30 14:57:46 -0800 | [diff] [blame] | 515 | return nil, status.Error(codes.InvalidArgument, err.Error()) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 516 | } |
| 517 | return volthaDevice, nil |
| 518 | } else { |
| 519 | unpackResult := &ic.Error{} |
| 520 | var err error |
| 521 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 522 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 523 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 524 | logger.Debugw(ctx, "GetChildDevice-return", log.Fields{"deviceid": parentDeviceId, "success": success, "error": err}) |
Matteo Scandolo | b45cf59 | 2020-01-21 16:10:56 -0800 | [diff] [blame] | 525 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 526 | return nil, status.Error(ICProxyErrorCodeToGrpcErrorCode(ctx, unpackResult.Code), unpackResult.Reason) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | |
| 530 | func (ap *CoreProxy) GetChildDevices(ctx context.Context, parentDeviceId string) (*voltha.Devices, error) { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 531 | logger.Debugw(ctx, "GetChildDevices", log.Fields{"parentDeviceId": parentDeviceId}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 532 | rpc := "GetChildDevices" |
| 533 | |
| 534 | toTopic := ap.getCoreTopic(parentDeviceId) |
| 535 | replyToTopic := ap.getAdapterTopic() |
| 536 | |
| 537 | args := make([]*kafka.KVArg, 1) |
| 538 | id := &voltha.ID{Id: parentDeviceId} |
| 539 | args[0] = &kafka.KVArg{ |
| 540 | Key: "device_id", |
| 541 | Value: id, |
| 542 | } |
| 543 | |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 544 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 545 | logger.Debugw(ctx, "GetChildDevices-response", log.Fields{"pDeviceId": parentDeviceId, "success": success}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 546 | |
| 547 | if success { |
| 548 | volthaDevices := &voltha.Devices{} |
| 549 | if err := ptypes.UnmarshalAny(result, volthaDevices); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 550 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
Matteo Scandolo | 1530d41 | 2020-01-30 14:57:46 -0800 | [diff] [blame] | 551 | return nil, status.Error(codes.InvalidArgument, err.Error()) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 552 | } |
| 553 | return volthaDevices, nil |
| 554 | } else { |
| 555 | unpackResult := &ic.Error{} |
| 556 | var err error |
| 557 | if err = ptypes.UnmarshalAny(result, unpackResult); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 558 | logger.Warnw(ctx, "cannot-unmarshal-response", log.Fields{"error": err}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 559 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 560 | logger.Debugw(ctx, "GetChildDevices-return", log.Fields{"deviceid": parentDeviceId, "success": success, "error": err}) |
Matteo Scandolo | b45cf59 | 2020-01-21 16:10:56 -0800 | [diff] [blame] | 561 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 562 | return nil, status.Error(ICProxyErrorCodeToGrpcErrorCode(ctx, unpackResult.Code), unpackResult.Reason) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
| 566 | func (ap *CoreProxy) SendPacketIn(ctx context.Context, deviceId string, port uint32, pktPayload []byte) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 567 | logger.Debugw(ctx, "SendPacketIn", log.Fields{"deviceId": deviceId, "port": port, "pktPayload": pktPayload}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 568 | rpc := "PacketIn" |
| 569 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 570 | // specific topic |
| 571 | toTopic := ap.getCoreTopic(deviceId) |
| 572 | replyToTopic := ap.getAdapterTopic() |
| 573 | |
| 574 | args := make([]*kafka.KVArg, 3) |
| 575 | id := &voltha.ID{Id: deviceId} |
| 576 | args[0] = &kafka.KVArg{ |
| 577 | Key: "device_id", |
| 578 | Value: id, |
| 579 | } |
| 580 | portNo := &ic.IntType{Val: int64(port)} |
| 581 | args[1] = &kafka.KVArg{ |
| 582 | Key: "port", |
| 583 | Value: portNo, |
| 584 | } |
| 585 | pkt := &ic.Packet{Payload: pktPayload} |
| 586 | args[2] = &kafka.KVArg{ |
| 587 | Key: "packet", |
| 588 | Value: pkt, |
| 589 | } |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 590 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 591 | logger.Debugw(ctx, "SendPacketIn-response", log.Fields{"pDeviceId": deviceId, "success": success}) |
| 592 | return unPackResponse(ctx, rpc, deviceId, success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 593 | } |
| 594 | |
David Bainbridge | 36d0b20 | 2019-10-23 18:33:34 +0000 | [diff] [blame] | 595 | func (ap *CoreProxy) DeviceReasonUpdate(ctx context.Context, deviceId string, deviceReason string) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 596 | logger.Debugw(ctx, "DeviceReasonUpdate", log.Fields{"deviceId": deviceId, "deviceReason": deviceReason}) |
David Bainbridge | 36d0b20 | 2019-10-23 18:33:34 +0000 | [diff] [blame] | 597 | rpc := "DeviceReasonUpdate" |
| 598 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 599 | // specific topic |
| 600 | toTopic := ap.getCoreTopic(deviceId) |
| 601 | replyToTopic := ap.getAdapterTopic() |
| 602 | |
| 603 | args := make([]*kafka.KVArg, 2) |
| 604 | id := &voltha.ID{Id: deviceId} |
| 605 | args[0] = &kafka.KVArg{ |
| 606 | Key: "device_id", |
| 607 | Value: id, |
| 608 | } |
| 609 | reason := &ic.StrType{Val: deviceReason} |
| 610 | args[1] = &kafka.KVArg{ |
| 611 | Key: "device_reason", |
| 612 | Value: reason, |
| 613 | } |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 614 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 615 | logger.Debugw(ctx, "DeviceReason-response", log.Fields{"pDeviceId": deviceId, "success": success}) |
| 616 | return unPackResponse(ctx, rpc, deviceId, success, result) |
David Bainbridge | 36d0b20 | 2019-10-23 18:33:34 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 619 | func (ap *CoreProxy) DevicePMConfigUpdate(ctx context.Context, pmConfigs *voltha.PmConfigs) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 620 | logger.Debugw(ctx, "DevicePMConfigUpdate", log.Fields{"pmConfigs": pmConfigs}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 621 | rpc := "DevicePMConfigUpdate" |
| 622 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 623 | // specific topic |
| 624 | toTopic := ap.getCoreTopic(pmConfigs.Id) |
| 625 | replyToTopic := ap.getAdapterTopic() |
| 626 | |
| 627 | args := make([]*kafka.KVArg, 1) |
| 628 | args[0] = &kafka.KVArg{ |
| 629 | Key: "device_pm_config", |
| 630 | Value: pmConfigs, |
| 631 | } |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 632 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, pmConfigs.Id, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 633 | logger.Debugw(ctx, "DevicePMConfigUpdate-response", log.Fields{"pDeviceId": pmConfigs.Id, "success": success}) |
| 634 | return unPackResponse(ctx, rpc, pmConfigs.Id, success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | func (ap *CoreProxy) ReconcileChildDevices(ctx context.Context, parentDeviceId string) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 638 | logger.Debugw(ctx, "ReconcileChildDevices", log.Fields{"parentDeviceId": parentDeviceId}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 639 | rpc := "ReconcileChildDevices" |
| 640 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 641 | // specific topic |
| 642 | toTopic := ap.getCoreTopic(parentDeviceId) |
| 643 | replyToTopic := ap.getAdapterTopic() |
| 644 | |
| 645 | args := []*kafka.KVArg{ |
| 646 | {Key: "parent_device_id", Value: &voltha.ID{Id: parentDeviceId}}, |
| 647 | } |
| 648 | |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 649 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, parentDeviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 650 | logger.Debugw(ctx, "ReconcileChildDevices-response", log.Fields{"pDeviceId": parentDeviceId, "success": success}) |
| 651 | return unPackResponse(ctx, rpc, parentDeviceId, success, result) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 652 | } |
Chaitrashree G S | 66d4135 | 2020-01-09 20:18:58 -0500 | [diff] [blame] | 653 | |
| 654 | func (ap *CoreProxy) PortStateUpdate(ctx context.Context, deviceId string, pType voltha.Port_PortType, portNum uint32, |
serkant.uluderya | b38671c | 2019-11-01 09:35:38 -0700 | [diff] [blame] | 655 | operStatus voltha.OperStatus_Types) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 656 | logger.Debugw(ctx, "PortStateUpdate", log.Fields{"deviceId": deviceId, "portType": pType, "portNo": portNum, "operation_status": operStatus}) |
Chaitrashree G S | 66d4135 | 2020-01-09 20:18:58 -0500 | [diff] [blame] | 657 | rpc := "PortStateUpdate" |
| 658 | // Use a device specific topic to send the request. The adapter handling the device creates a device |
| 659 | // specific topic |
| 660 | toTopic := ap.getCoreTopic(deviceId) |
| 661 | args := make([]*kafka.KVArg, 4) |
| 662 | deviceID := &voltha.ID{Id: deviceId} |
| 663 | portNo := &ic.IntType{Val: int64(portNum)} |
| 664 | portType := &ic.IntType{Val: int64(pType)} |
| 665 | oStatus := &ic.IntType{Val: int64(operStatus)} |
| 666 | |
| 667 | args[0] = &kafka.KVArg{ |
| 668 | Key: "device_id", |
| 669 | Value: deviceID, |
| 670 | } |
| 671 | args[1] = &kafka.KVArg{ |
| 672 | Key: "oper_status", |
| 673 | Value: oStatus, |
| 674 | } |
| 675 | args[2] = &kafka.KVArg{ |
| 676 | Key: "port_type", |
| 677 | Value: portType, |
| 678 | } |
| 679 | args[3] = &kafka.KVArg{ |
| 680 | Key: "port_no", |
| 681 | Value: portNo, |
| 682 | } |
| 683 | |
| 684 | // Use a device specific topic as we are the only adaptercore handling requests for this device |
| 685 | replyToTopic := ap.getAdapterTopic() |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 686 | success, result := ap.kafkaICProxy.InvokeRPC(context.Background(), rpc, &toTopic, &replyToTopic, true, deviceId, args...) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 687 | logger.Debugw(ctx, "PortStateUpdate-response", log.Fields{"deviceId": deviceId, "success": success}) |
| 688 | return unPackResponse(ctx, rpc, deviceId, success, result) |
Chaitrashree G S | 66d4135 | 2020-01-09 20:18:58 -0500 | [diff] [blame] | 689 | } |