blob: 759ff3fbbd3c1c9047f91a6fee98a58572315216 [file] [log] [blame]
Phaneendra Manda4c62c802019-03-06 21:37:49 +05301/*
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 */
16package adaptercore
17
18import (
cuilin20187b2a8c32019-03-26 19:52:28 -070019 "context"
20 "errors"
21 "fmt"
22 "io"
23 "strconv"
24 "strings"
25 "sync"
26 "time"
Phaneendra Manda4c62c802019-03-06 21:37:49 +053027
cuilin20187b2a8c32019-03-26 19:52:28 -070028 "github.com/gogo/protobuf/proto"
29 "github.com/golang/protobuf/ptypes"
manikkaraj k9eb6cac2019-05-09 12:32:03 -040030 "github.com/mdlayher/ethernet"
cuilin20187b2a8c32019-03-26 19:52:28 -070031 com "github.com/opencord/voltha-go/adapters/common"
32 "github.com/opencord/voltha-go/common/log"
Girish Gowdru0c588b22019-04-23 23:24:56 -040033 rsrcMgr "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager"
manikkaraj kbf256be2019-03-25 00:13:48 +053034 "github.com/opencord/voltha-protos/go/common"
35 ic "github.com/opencord/voltha-protos/go/inter_container"
36 of "github.com/opencord/voltha-protos/go/openflow_13"
37 oop "github.com/opencord/voltha-protos/go/openolt"
manikkaraj kbf256be2019-03-25 00:13:48 +053038 "github.com/opencord/voltha-protos/go/voltha"
cuilin20187b2a8c32019-03-26 19:52:28 -070039 "google.golang.org/grpc"
Phaneendra Manda4c62c802019-03-06 21:37:49 +053040)
41
42//DeviceHandler will interact with the OLT device.
43type DeviceHandler struct {
cuilin20187b2a8c32019-03-26 19:52:28 -070044 deviceId string
45 deviceType string
Girish Gowdru5ba46c92019-04-25 05:00:05 -040046 adminState string
cuilin20187b2a8c32019-03-26 19:52:28 -070047 device *voltha.Device
48 coreProxy *com.CoreProxy
manikkaraj kbf256be2019-03-25 00:13:48 +053049 AdapterProxy *com.AdapterProxy
cuilin20187b2a8c32019-03-26 19:52:28 -070050 openOLT *OpenOLT
51 nniPort *voltha.Port
52 ponPort *voltha.Port
53 exitChannel chan int
54 lockDevice sync.RWMutex
manikkaraj kbf256be2019-03-25 00:13:48 +053055 Client oop.OpenoltClient
cuilin20187b2a8c32019-03-26 19:52:28 -070056 transitionMap *TransitionMap
57 clientCon *grpc.ClientConn
manikkaraj kbf256be2019-03-25 00:13:48 +053058 flowMgr *OpenOltFlowMgr
59 resourceMgr *rsrcMgr.OpenOltResourceMgr
Phaneendra Manda4c62c802019-03-06 21:37:49 +053060}
61
62//NewDeviceHandler creates a new device handler
cuilin20187b2a8c32019-03-26 19:52:28 -070063func NewDeviceHandler(cp *com.CoreProxy, ap *com.AdapterProxy, device *voltha.Device, adapter *OpenOLT) *DeviceHandler {
64 var dh DeviceHandler
65 dh.coreProxy = cp
Girish Gowdru0c588b22019-04-23 23:24:56 -040066 dh.AdapterProxy = ap
cuilin20187b2a8c32019-03-26 19:52:28 -070067 cloned := (proto.Clone(device)).(*voltha.Device)
68 dh.deviceId = cloned.Id
69 dh.deviceType = cloned.Type
Girish Gowdru5ba46c92019-04-25 05:00:05 -040070 dh.adminState = "up"
cuilin20187b2a8c32019-03-26 19:52:28 -070071 dh.device = cloned
72 dh.openOLT = adapter
73 dh.exitChannel = make(chan int, 1)
74 dh.lockDevice = sync.RWMutex{}
Phaneendra Manda4c62c802019-03-06 21:37:49 +053075
cuilin20187b2a8c32019-03-26 19:52:28 -070076 //TODO initialize the support classes.
77 return &dh
Phaneendra Manda4c62c802019-03-06 21:37:49 +053078}
79
80// start save the device to the data model
81func (dh *DeviceHandler) start(ctx context.Context) {
cuilin20187b2a8c32019-03-26 19:52:28 -070082 dh.lockDevice.Lock()
83 defer dh.lockDevice.Unlock()
84 log.Debugw("starting-device-agent", log.Fields{"device": dh.device})
85 // Add the initial device to the local model
86 log.Debug("device-agent-started")
Phaneendra Manda4c62c802019-03-06 21:37:49 +053087}
88
89// stop stops the device dh. Not much to do for now
90func (dh *DeviceHandler) stop(ctx context.Context) {
cuilin20187b2a8c32019-03-26 19:52:28 -070091 dh.lockDevice.Lock()
92 defer dh.lockDevice.Unlock()
93 log.Debug("stopping-device-agent")
94 dh.exitChannel <- 1
95 log.Debug("device-agent-stopped")
Phaneendra Manda4c62c802019-03-06 21:37:49 +053096}
97
98func macAddressToUint32Array(mac string) []uint32 {
cuilin20187b2a8c32019-03-26 19:52:28 -070099 slist := strings.Split(mac, ":")
100 result := make([]uint32, len(slist))
101 var err error
102 var tmp int64
103 for index, val := range slist {
104 if tmp, err = strconv.ParseInt(val, 16, 32); err != nil {
105 return []uint32{1, 2, 3, 4, 5, 6}
106 }
107 result[index] = uint32(tmp)
108 }
109 return result
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530110}
111
manikkaraj kbf256be2019-03-25 00:13:48 +0530112func GetportLabel(portNum uint32, portType voltha.Port_PortType) string {
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530113
Girish Gowdru0c588b22019-04-23 23:24:56 -0400114 if portType == voltha.Port_ETHERNET_NNI {
115 return fmt.Sprintf("nni-%d", portNum)
116 } else if portType == voltha.Port_PON_OLT {
117 return fmt.Sprintf("pon-%d", portNum)
cuilin20187b2a8c32019-03-26 19:52:28 -0700118 } else if portType == voltha.Port_ETHERNET_UNI {
119 log.Errorw("local UNI management not supported", log.Fields{})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400120 return ""
cuilin20187b2a8c32019-03-26 19:52:28 -0700121 }
122 return ""
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530123}
124
125func (dh *DeviceHandler) addPort(intfId uint32, portType voltha.Port_PortType, state string) {
cuilin20187b2a8c32019-03-26 19:52:28 -0700126 var operStatus common.OperStatus_OperStatus
127 if state == "up" {
128 operStatus = voltha.OperStatus_ACTIVE
129 } else {
130 operStatus = voltha.OperStatus_DISCOVERED
131 }
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400132 portNum := IntfIdToPortNo(intfId, portType)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400133 label := GetportLabel(portNum, portType)
134 if len(label) == 0 {
135 log.Errorw("Invalid-port-label", log.Fields{"portNum": portNum, "portType": portType})
136 return
137 }
138 // Now create Port
139 port := &voltha.Port{
cuilin20187b2a8c32019-03-26 19:52:28 -0700140 PortNo: portNum,
141 Label: label,
142 Type: portType,
143 OperStatus: operStatus,
144 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400145 log.Debugw("Sending port update to core", log.Fields{"port": port})
cuilin20187b2a8c32019-03-26 19:52:28 -0700146 // Synchronous call to update device - this method is run in its own go routine
Girish Gowdru0c588b22019-04-23 23:24:56 -0400147 if err := dh.coreProxy.PortCreated(nil, dh.device.Id, port); err != nil {
cuilin20187b2a8c32019-03-26 19:52:28 -0700148 log.Errorw("error-creating-nni-port", log.Fields{"deviceId": dh.device.Id, "error": err})
149 }
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530150}
151
152// readIndications to read the indications from the OLT device
153func (dh *DeviceHandler) readIndications() {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400154 indications, err := dh.Client.EnableIndication(context.Background(), new(oop.Empty))
cuilin20187b2a8c32019-03-26 19:52:28 -0700155 if err != nil {
156 log.Errorw("Failed to read indications", log.Fields{"err": err})
157 return
158 }
159 if indications == nil {
160 log.Errorw("Indications is nil", log.Fields{})
161 return
162 }
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400163 /* get device state */
164 device, err := dh.coreProxy.GetDevice(nil, dh.device.Id, dh.device.Id)
165 if err != nil || device == nil {
166 /*TODO: needs to handle error scenarios */
167 log.Errorw("Failed to fetch device info", log.Fields{"err": err})
168
169 }
170 // When the device is in DISABLED and Adapter container restarts, we need to
171 // rebuild the locally maintained admin state.
172 if device.AdminState == voltha.AdminState_DISABLED {
173 dh.lockDevice.Lock()
174 dh.adminState = "down"
175 dh.lockDevice.Unlock()
176 }
177
cuilin20187b2a8c32019-03-26 19:52:28 -0700178 for {
179 indication, err := indications.Recv()
180 if err == io.EOF {
181 break
182 }
183 if err != nil {
184 log.Infow("Failed to read from indications", log.Fields{"err": err})
Girish Gowdrud4245152019-05-10 00:47:31 -0400185 dh.transitionMap.Handle(DeviceDownInd)
186 dh.transitionMap.Handle(DeviceInit)
187 break
cuilin20187b2a8c32019-03-26 19:52:28 -0700188 }
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400189 // When OLT is admin down, allow only NNI operation status change indications.
190 if dh.adminState == "down" {
191 _, isIntfOperInd := indication.Data.(*oop.Indication_IntfOperInd)
192 if isIntfOperInd {
193 intfOperInd := indication.GetIntfOperInd()
194 if intfOperInd.GetType() == "nni" {
195 log.Infow("olt is admin down, allow nni ind", log.Fields{})
196 }
197 } else {
198 log.Infow("olt is admin down, ignore indication", log.Fields{})
199 continue
200 }
201 }
cuilin20187b2a8c32019-03-26 19:52:28 -0700202 switch indication.Data.(type) {
203 case *oop.Indication_OltInd:
204 oltInd := indication.GetOltInd()
205 if oltInd.OperState == "up" {
206 dh.transitionMap.Handle(DeviceUpInd)
207 } else if oltInd.OperState == "down" {
208 dh.transitionMap.Handle(DeviceDownInd)
209 }
210 case *oop.Indication_IntfInd:
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530211
cuilin20187b2a8c32019-03-26 19:52:28 -0700212 intfInd := indication.GetIntfInd()
213 go dh.addPort(intfInd.GetIntfId(), voltha.Port_PON_OLT, intfInd.GetOperState())
214 log.Infow("Received interface indication ", log.Fields{"InterfaceInd": intfInd})
215 case *oop.Indication_IntfOperInd:
216 intfOperInd := indication.GetIntfOperInd()
217 if intfOperInd.GetType() == "nni" {
218 go dh.addPort(intfOperInd.GetIntfId(), voltha.Port_ETHERNET_NNI, intfOperInd.GetOperState())
219 } else if intfOperInd.GetType() == "pon" {
220 // TODO: Check what needs to be handled here for When PON PORT down, ONU will be down
221 // Handle pon port update
222 }
223 log.Infow("Received interface oper indication ", log.Fields{"InterfaceOperInd": intfOperInd})
224 case *oop.Indication_OnuDiscInd:
225 onuDiscInd := indication.GetOnuDiscInd()
226 log.Infow("Received Onu discovery indication ", log.Fields{"OnuDiscInd": onuDiscInd})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400227 //onuId,err := dh.resourceMgr.GetONUID(onuDiscInd.GetIntfId())
228 //onuId,err := dh.resourceMgr.GetONUID(onuDiscInd.GetIntfId())
229 // TODO Get onu ID from the resource manager
cuilin20187b2a8c32019-03-26 19:52:28 -0700230 var onuId uint32 = 1
Girish Gowdru0c588b22019-04-23 23:24:56 -0400231 /*if err != nil{
232 log.Errorw("onu-id-unavailable",log.Fields{"intfId":onuDiscInd.GetIntfId()})
233 return
234 }*/
manikkaraj kbf256be2019-03-25 00:13:48 +0530235
cuilin20187b2a8c32019-03-26 19:52:28 -0700236 sn := dh.stringifySerialNumber(onuDiscInd.SerialNumber)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400237 //FIXME: Duplicate child devices being create in go routine
238 dh.onuDiscIndication(onuDiscInd, onuId, sn)
cuilin20187b2a8c32019-03-26 19:52:28 -0700239 case *oop.Indication_OnuInd:
240 onuInd := indication.GetOnuInd()
241 log.Infow("Received Onu indication ", log.Fields{"OnuInd": onuInd})
242 go dh.onuIndication(onuInd)
243 case *oop.Indication_OmciInd:
244 omciInd := indication.GetOmciInd()
245 log.Infow("Received Omci indication ", log.Fields{"OmciInd": omciInd})
246 if err := dh.omciIndication(omciInd); err != nil {
247 log.Errorw("send-omci-indication-errr", log.Fields{"error": err, "omciInd": omciInd})
248 }
249 case *oop.Indication_PktInd:
250 pktInd := indication.GetPktInd()
251 log.Infow("Received pakcet indication ", log.Fields{"PktInd": pktInd})
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400252 go dh.handlePacketIndication(pktInd)
cuilin20187b2a8c32019-03-26 19:52:28 -0700253 case *oop.Indication_PortStats:
254 portStats := indication.GetPortStats()
255 log.Infow("Received port stats indication", log.Fields{"PortStats": portStats})
256 case *oop.Indication_FlowStats:
257 flowStats := indication.GetFlowStats()
258 log.Infow("Received flow stats", log.Fields{"FlowStats": flowStats})
259 case *oop.Indication_AlarmInd:
260 alarmInd := indication.GetAlarmInd()
261 log.Infow("Received alarm indication ", log.Fields{"AlarmInd": alarmInd})
262 }
263 }
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530264}
265
266// doStateUp handle the olt up indication and update to voltha core
267func (dh *DeviceHandler) doStateUp() error {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400268 // Synchronous call to update device state - this method is run in its own go routine
cuilin20187b2a8c32019-03-26 19:52:28 -0700269 if err := dh.coreProxy.DeviceStateUpdate(context.Background(), dh.device.Id, voltha.ConnectStatus_REACHABLE,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400270 voltha.OperStatus_ACTIVE); err != nil {
271 log.Errorw("Failed to update device with OLT UP indication", log.Fields{"deviceId": dh.device.Id, "error": err})
272 return err
273 }
274 return nil
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530275}
276
277// doStateDown handle the olt down indication
278func (dh *DeviceHandler) doStateDown() error {
Girish Gowdrud4245152019-05-10 00:47:31 -0400279 log.Debug("do-state-down-start")
280
281 device, err := dh.coreProxy.GetDevice(nil, dh.device.Id, dh.device.Id)
282 if err != nil || device == nil {
283 /*TODO: needs to handle error scenarios */
284 log.Errorw("Failed to fetch device device", log.Fields{"err": err})
285 }
286
287 cloned := proto.Clone(device).(*voltha.Device)
288 // Update the all ports state on that device to disable
289 if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
290 log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
291 return err
292 }
293
294 //Update the device oper state and connection status
295 cloned.OperStatus = voltha.OperStatus_UNKNOWN
296 cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE
297 dh.device = cloned
298
299 if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
300 log.Errorw("error-updating-device-state", log.Fields{"deviceId": device.Id, "error": err})
301 return err
302 }
303 log.Debugw("do-state-down-end", log.Fields{"deviceId": device.Id})
cuilin20187b2a8c32019-03-26 19:52:28 -0700304 return nil
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530305}
306
307// doStateInit dial the grpc before going to init state
308func (dh *DeviceHandler) doStateInit() error {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400309 var err error
Girish Gowdrud4245152019-05-10 00:47:31 -0400310 dh.clientCon, err = grpc.Dial(dh.device.GetHostAndPort(), grpc.WithInsecure(), grpc.WithBlock())
Girish Gowdru0c588b22019-04-23 23:24:56 -0400311 if err != nil {
cuilin20187b2a8c32019-03-26 19:52:28 -0700312 log.Errorw("Failed to dial device", log.Fields{"DeviceId": dh.deviceId, "HostAndPort": dh.device.GetHostAndPort(), "err": err})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400313 return err
314 }
315 return nil
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530316}
317
318// postInit create olt client instance to invoke RPC on the olt device
319func (dh *DeviceHandler) postInit() error {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400320 dh.Client = oop.NewOpenoltClient(dh.clientCon)
321 dh.transitionMap.Handle(GrpcConnected)
322 return nil
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530323}
324
325// doStateConnected get the device info and update to voltha core
326func (dh *DeviceHandler) doStateConnected() error {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400327 log.Debug("OLT device has been connected")
328 deviceInfo, err := dh.Client.GetDeviceInfo(context.Background(), new(oop.Empty))
cuilin20187b2a8c32019-03-26 19:52:28 -0700329 if err != nil {
330 log.Errorw("Failed to fetch device info", log.Fields{"err": err})
331 return err
332 }
333 if deviceInfo == nil {
334 log.Errorw("Device info is nil", log.Fields{})
335 return errors.New("Failed to get device info from OLT")
336 }
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400337 log.Debugw("Fetched device info", log.Fields{"deviceInfo": deviceInfo})
cuilin20187b2a8c32019-03-26 19:52:28 -0700338 dh.device.Root = true
339 dh.device.Vendor = deviceInfo.Vendor
340 dh.device.Model = deviceInfo.Model
341 dh.device.ConnectStatus = voltha.ConnectStatus_REACHABLE
342 dh.device.SerialNumber = deviceInfo.DeviceSerialNumber
343 dh.device.HardwareVersion = deviceInfo.HardwareVersion
344 dh.device.FirmwareVersion = deviceInfo.FirmwareVersion
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400345 // FIXME: Remove Hardcodings
cuilin20187b2a8c32019-03-26 19:52:28 -0700346 dh.device.MacAddress = "0a:0b:0c:0d:0e:0f"
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530347
cuilin20187b2a8c32019-03-26 19:52:28 -0700348 // Synchronous call to update device - this method is run in its own go routine
349 if err := dh.coreProxy.DeviceUpdate(nil, dh.device); err != nil {
350 log.Errorw("error-updating-device", log.Fields{"deviceId": dh.device.Id, "error": err})
351 }
Girish Gowdrud4245152019-05-10 00:47:31 -0400352
353 device, err := dh.coreProxy.GetDevice(nil, dh.device.Id, dh.device.Id)
354 if err != nil || device == nil {
355 /*TODO: needs to handle error scenarios */
356 log.Errorw("Failed to fetch device device", log.Fields{"err": err})
357 }
358 cloned := proto.Clone(device).(*voltha.Device)
359 // Update the all ports (if available) on that device to ACTIVE.
360 // The ports do not normally exist, unless the device is coming back from a reboot
361 if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
362 log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
363 return err
364 }
365
Girish Gowdru0c588b22019-04-23 23:24:56 -0400366 KVStoreHostPort := fmt.Sprintf("%s:%d", dh.openOLT.KVStoreHost, dh.openOLT.KVStorePort)
367 // Instantiate resource manager
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400368 if dh.resourceMgr = rsrcMgr.NewResourceMgr(dh.deviceId, KVStoreHostPort, dh.openOLT.KVStoreType, dh.deviceType, deviceInfo); dh.resourceMgr == nil {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400369 log.Error("Error while instantiating resource manager")
370 return errors.New("Instantiating resource manager failed")
371 }
372 // Instantiate flow manager
373 if dh.flowMgr = NewFlowManager(dh, dh.resourceMgr); dh.flowMgr == nil {
374 log.Error("Error while instantiating flow manager")
375 return errors.New("Instantiating flow manager failed")
376 }
377 /* TODO: Instantiate Alarm , stats , BW managers */
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530378
cuilin20187b2a8c32019-03-26 19:52:28 -0700379 // Start reading indications
380 go dh.readIndications()
381 return nil
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530382}
383
384// AdoptDevice adopts the OLT device
385func (dh *DeviceHandler) AdoptDevice(device *voltha.Device) {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400386 dh.transitionMap = NewTransitionMap(dh)
cuilin20187b2a8c32019-03-26 19:52:28 -0700387 log.Infow("AdoptDevice", log.Fields{"deviceId": device.Id, "Address": device.GetHostAndPort()})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400388 dh.transitionMap.Handle(DeviceInit)
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530389}
390
391// GetOfpDeviceInfo Get the Ofp device information
392func (dh *DeviceHandler) GetOfpDeviceInfo(device *voltha.Device) (*ic.SwitchCapability, error) {
cuilin20187b2a8c32019-03-26 19:52:28 -0700393 return &ic.SwitchCapability{
394 Desc: &of.OfpDesc{
395 HwDesc: "open_pon",
396 SwDesc: "open_pon",
397 SerialNum: dh.device.SerialNumber,
398 },
399 SwitchFeatures: &of.OfpSwitchFeatures{
400 NBuffers: 256,
401 NTables: 2,
402 Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS |
403 of.OfpCapabilities_OFPC_TABLE_STATS |
404 of.OfpCapabilities_OFPC_PORT_STATS |
405 of.OfpCapabilities_OFPC_GROUP_STATS),
406 },
407 }, nil
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530408}
409
410// GetOfpPortInfo Get Ofp port information
411func (dh *DeviceHandler) GetOfpPortInfo(device *voltha.Device, portNo int64) (*ic.PortCapability, error) {
cuilin20187b2a8c32019-03-26 19:52:28 -0700412 cap := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
413 return &ic.PortCapability{
414 Port: &voltha.LogicalPort{
415 OfpPort: &of.OfpPort{
416 HwAddr: macAddressToUint32Array(dh.device.MacAddress),
417 Config: 0,
418 State: uint32(of.OfpPortState_OFPPS_LIVE),
419 Curr: cap,
420 Advertised: cap,
421 Peer: cap,
422 CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
423 MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
424 },
425 DeviceId: dh.device.Id,
426 DevicePortNo: uint32(portNo),
427 },
428 }, nil
429}
430
431func (dh *DeviceHandler) omciIndication(omciInd *oop.OmciIndication) error {
432 log.Debugw("omci indication", log.Fields{"intfId": omciInd.IntfId, "onuId": omciInd.OnuId})
433
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400434 ponPort := IntfIdToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT)
cuilin20187b2a8c32019-03-26 19:52:28 -0700435 kwargs := make(map[string]interface{})
436 kwargs["onu_id"] = omciInd.OnuId
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400437 kwargs["parent_port_no"] = ponPort
cuilin20187b2a8c32019-03-26 19:52:28 -0700438
439 if onuDevice, err := dh.coreProxy.GetChildDevice(nil, dh.device.Id, kwargs); err != nil {
440 log.Errorw("onu not found", log.Fields{"intfId": omciInd.IntfId, "onuId": omciInd.OnuId})
441 return err
442 } else {
443 omciMsg := &ic.InterAdapterOmciMessage{Message: omciInd.Pkt}
manikkaraj kbf256be2019-03-25 00:13:48 +0530444 if sendErr := dh.AdapterProxy.SendInterAdapterMessage(context.Background(), omciMsg,
cuilin20187b2a8c32019-03-26 19:52:28 -0700445 ic.InterAdapterMessageType_OMCI_REQUEST, dh.deviceType, onuDevice.Type,
446 onuDevice.Id, onuDevice.ProxyAddress.DeviceId, ""); sendErr != nil {
447 log.Errorw("send omci request error", log.Fields{"fromAdapter": dh.deviceType, "toAdapter": onuDevice.Type, "onuId": onuDevice.Id, "proxyDeviceId": onuDevice.ProxyAddress.DeviceId})
448 return sendErr
449 }
450 return nil
451 }
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530452}
453
454// Process_inter_adapter_message process inter adater message
455func (dh *DeviceHandler) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
cuilin20187b2a8c32019-03-26 19:52:28 -0700456 log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
457 if msg.Header.Type == ic.InterAdapterMessageType_OMCI_REQUEST {
458 msgId := msg.Header.Id
459 fromTopic := msg.Header.FromTopic
460 toTopic := msg.Header.ToTopic
461 toDeviceId := msg.Header.ToDeviceId
462 proxyDeviceId := msg.Header.ProxyDeviceId
463
464 log.Debugw("omci request message header", log.Fields{"msgId": msgId, "fromTopic": fromTopic, "toTopic": toTopic, "toDeviceId": toDeviceId, "proxyDeviceId": proxyDeviceId})
465
466 msgBody := msg.GetBody()
467
468 omciMsg := &ic.InterAdapterOmciMessage{}
469 if err := ptypes.UnmarshalAny(msgBody, omciMsg); err != nil {
470 log.Warnw("cannot-unmarshal-omci-msg-body", log.Fields{"error": err})
471 return err
472 }
473
474 if onuDevice, err := dh.coreProxy.GetDevice(nil, dh.device.Id, toDeviceId); err != nil {
475 log.Errorw("onu not found", log.Fields{"onuDeviceId": toDeviceId, "error": err})
476 return err
477 } else {
478 dh.sendProxiedMessage(onuDevice, omciMsg)
479 }
480
481 } else {
482 log.Errorw("inter-adapter-unhandled-type", log.Fields{"msgType": msg.Header.Type})
483 }
484 return nil
Phaneendra Manda4c62c802019-03-06 21:37:49 +0530485}
486
cuilin20187b2a8c32019-03-26 19:52:28 -0700487func (dh *DeviceHandler) sendProxiedMessage(onuDevice *voltha.Device, omciMsg *ic.InterAdapterOmciMessage) {
488 if onuDevice.ConnectStatus != voltha.ConnectStatus_REACHABLE {
489 log.Debugw("ONU is not reachable, cannot send OMCI", log.Fields{"serialNumber": onuDevice.SerialNumber, "intfId": onuDevice.ProxyAddress.GetChannelId(), "onuId": onuDevice.ProxyAddress.GetOnuId()})
490 return
491 }
492
493 omciMessage := &oop.OmciMsg{IntfId: onuDevice.ProxyAddress.GetChannelId(), OnuId: onuDevice.ProxyAddress.GetOnuId(), Pkt: omciMsg.Message}
494
manikkaraj kbf256be2019-03-25 00:13:48 +0530495 dh.Client.OmciMsgOut(context.Background(), omciMessage)
cuilin20187b2a8c32019-03-26 19:52:28 -0700496 log.Debugw("omci-message-sent", log.Fields{"serialNumber": onuDevice.SerialNumber, "intfId": onuDevice.ProxyAddress.GetChannelId(), "omciMsg": string(omciMsg.Message)})
497}
498
499func (dh *DeviceHandler) activateONU(intfId uint32, onuId int64, serialNum *oop.SerialNumber, serialNumber string) {
500 log.Debugw("activate-onu", log.Fields{"intfId": intfId, "onuId": onuId, "serialNum": serialNum, "serialNumber": serialNumber})
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400501 dh.flowMgr.UpdateOnuInfo(intfId, uint32(onuId), serialNumber)
cuilin20187b2a8c32019-03-26 19:52:28 -0700502 // TODO: need resource manager
503 var pir uint32 = 1000000
504 Onu := oop.Onu{IntfId: intfId, OnuId: uint32(onuId), SerialNumber: serialNum, Pir: pir}
manikkaraj kbf256be2019-03-25 00:13:48 +0530505 if _, err := dh.Client.ActivateOnu(context.Background(), &Onu); err != nil {
cuilin20187b2a8c32019-03-26 19:52:28 -0700506 log.Errorw("activate-onu-failed", log.Fields{"Onu": Onu})
507 } else {
508 log.Infow("activated-onu", log.Fields{"SerialNumber": serialNumber})
509 }
510}
511
512func (dh *DeviceHandler) onuDiscIndication(onuDiscInd *oop.OnuDiscIndication, onuId uint32, sn string) error {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400513 channelId := onuDiscInd.GetIntfId()
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400514 parentPortNo := IntfIdToPortNo(onuDiscInd.GetIntfId(), voltha.Port_PON_OLT)
manikkaraj kbf256be2019-03-25 00:13:48 +0530515 if err := dh.coreProxy.ChildDeviceDetected(nil, dh.device.Id, int(parentPortNo), "brcm_openomci_onu", int(channelId), string(onuDiscInd.SerialNumber.GetVendorId()), sn, int64(onuId)); err != nil {
cuilin20187b2a8c32019-03-26 19:52:28 -0700516 log.Errorw("Create onu error", log.Fields{"parent_id": dh.device.Id, "ponPort": onuDiscInd.GetIntfId(), "onuId": onuId, "sn": sn, "error": err})
517 return err
518 }
519
520 kwargs := make(map[string]interface{})
521 kwargs["onu_id"] = onuId
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400522 kwargs["parent_port_no"] = parentPortNo
cuilin20187b2a8c32019-03-26 19:52:28 -0700523
524 for i := 0; i < 10; i++ {
525 if onuDevice, _ := dh.coreProxy.GetChildDevice(nil, dh.device.Id, kwargs); onuDevice != nil {
526 dh.activateONU(onuDiscInd.IntfId, int64(onuId), onuDiscInd.SerialNumber, sn)
527 return nil
528 } else {
529 time.Sleep(1 * time.Second)
530 log.Debugln("Sleep 1 seconds to active onu, retry times ", i+1)
531 }
532 }
533 log.Errorw("Cannot query onu, dont activate it.", log.Fields{"parent_id": dh.device.Id, "ponPort": onuDiscInd.GetIntfId(), "onuId": onuId, "sn": sn})
534 return errors.New("Failed to activate onu")
535}
536
537func (dh *DeviceHandler) onuIndication(onuInd *oop.OnuIndication) {
538 serialNumber := dh.stringifySerialNumber(onuInd.SerialNumber)
539
540 kwargs := make(map[string]interface{})
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400541 ponPort := IntfIdToPortNo(onuInd.GetIntfId(), voltha.Port_PON_OLT)
manikkaraj kbf256be2019-03-25 00:13:48 +0530542
cuilin20187b2a8c32019-03-26 19:52:28 -0700543 if serialNumber != "" {
544 kwargs["serial_number"] = serialNumber
545 } else {
546 kwargs["onu_id"] = onuInd.OnuId
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400547 kwargs["parent_port_no"] = ponPort
cuilin20187b2a8c32019-03-26 19:52:28 -0700548 }
549 if onuDevice, _ := dh.coreProxy.GetChildDevice(nil, dh.device.Id, kwargs); onuDevice != nil {
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400550 if onuDevice.ParentPortNo != ponPort {
cuilin20187b2a8c32019-03-26 19:52:28 -0700551 //log.Warnw("ONU-is-on-a-different-intf-id-now", log.Fields{"previousIntfId": intfIdFromPortNo(onuDevice.ParentPortNo), "currentIntfId": onuInd.GetIntfId()})
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400552 log.Warnw("ONU-is-on-a-different-intf-id-now", log.Fields{"previousIntfId": onuDevice.ParentPortNo, "currentIntfId": ponPort})
cuilin20187b2a8c32019-03-26 19:52:28 -0700553 }
554
555 if onuDevice.ProxyAddress.OnuId != onuInd.OnuId {
556 log.Warnw("ONU-id-mismatch, can happen if both voltha and the olt rebooted", log.Fields{"expected_onu_id": onuDevice.ProxyAddress.OnuId, "received_onu_id": onuInd.OnuId})
557 }
558
559 // adminState
560 if onuInd.AdminState == "down" {
561 if onuInd.OperState != "down" {
562 log.Errorw("ONU-admin-state-down-and-oper-status-not-down", log.Fields{"operState": onuInd.OperState})
563 // Forcing the oper state change code to execute
564 onuInd.OperState = "down"
565 }
566 // Port and logical port update is taken care of by oper state block
567 } else if onuInd.AdminState == "up" {
568 log.Debugln("received-onu-admin-state up")
569 } else {
570 log.Errorw("Invalid-or-not-implemented-admin-state", log.Fields{"received-admin-state": onuInd.AdminState})
571 }
572 log.Debugln("admin-state-dealt-with")
573
574 // operState
575 if onuInd.OperState == "down" {
576 if onuDevice.ConnectStatus != common.ConnectStatus_UNREACHABLE {
577 dh.coreProxy.DeviceStateUpdate(nil, onuDevice.Id, common.ConnectStatus_UNREACHABLE, onuDevice.OperStatus)
578 log.Debugln("onu-oper-state-is-down")
579 }
580 if onuDevice.OperStatus != common.OperStatus_DISCOVERED {
581 dh.coreProxy.DeviceStateUpdate(nil, onuDevice.Id, common.ConnectStatus_UNREACHABLE, common.OperStatus_DISCOVERED)
582 }
583 log.Debugw("inter-adapter-send-onu-ind", log.Fields{"onuIndication": onuInd})
584
585 // TODO NEW CORE do not hardcode adapter name. Handler needs Adapter reference
manikkaraj kbf256be2019-03-25 00:13:48 +0530586 dh.AdapterProxy.SendInterAdapterMessage(nil, onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
cuilin20187b2a8c32019-03-26 19:52:28 -0700587 } else if onuInd.OperState == "up" {
588 if onuDevice.ConnectStatus != common.ConnectStatus_REACHABLE {
589 dh.coreProxy.DeviceStateUpdate(nil, onuDevice.Id, common.ConnectStatus_REACHABLE, onuDevice.OperStatus)
590
591 }
592 if onuDevice.OperStatus != common.OperStatus_DISCOVERED {
593 log.Warnw("ignore onu indication", log.Fields{"intfId": onuInd.IntfId, "onuId": onuInd.OnuId, "operStatus": onuDevice.OperStatus, "msgOperStatus": onuInd.OperState})
594 return
595 }
manikkaraj kbf256be2019-03-25 00:13:48 +0530596 dh.AdapterProxy.SendInterAdapterMessage(nil, onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST, "openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
cuilin20187b2a8c32019-03-26 19:52:28 -0700597 } else {
598 log.Warnw("Not-implemented-or-invalid-value-of-oper-state", log.Fields{"operState": onuInd.OperState})
599 }
600 } else {
601 log.Errorw("onu not found", log.Fields{"intfId": onuInd.IntfId, "onuId": onuInd.OnuId})
602 return
603 }
604
605}
606
607func (dh *DeviceHandler) stringifySerialNumber(serialNum *oop.SerialNumber) string {
608 if serialNum != nil {
609 return string(serialNum.VendorId) + dh.stringifyVendorSpecific(serialNum.VendorSpecific)
610 } else {
611 return ""
612 }
613}
614
615func (dh *DeviceHandler) stringifyVendorSpecific(vendorSpecific []byte) string {
616 tmp := fmt.Sprintf("%x", (uint32(vendorSpecific[0])>>4)&0x0f) +
617 fmt.Sprintf("%x", (uint32(vendorSpecific[0]&0x0f))) +
618 fmt.Sprintf("%x", (uint32(vendorSpecific[1])>>4)&0x0f) +
619 fmt.Sprintf("%x", (uint32(vendorSpecific[1]))&0x0f) +
620 fmt.Sprintf("%x", (uint32(vendorSpecific[2])>>4)&0x0f) +
621 fmt.Sprintf("%x", (uint32(vendorSpecific[2]))&0x0f) +
622 fmt.Sprintf("%x", (uint32(vendorSpecific[3])>>4)&0x0f) +
623 fmt.Sprintf("%x", (uint32(vendorSpecific[3]))&0x0f)
624 return tmp
625}
626
627// flows
628func (dh *DeviceHandler) Update_flows_bulk() error {
629 return errors.New("UnImplemented")
630}
Girish Gowdru0c588b22019-04-23 23:24:56 -0400631func (dh *DeviceHandler) GetChildDevice(parentPort uint32, onuId uint32) *voltha.Device {
632 log.Debugw("GetChildDevice", log.Fields{"pon port": parentPort, "onuId": onuId})
633 kwargs := make(map[string]interface{})
634 kwargs["onu_id"] = onuId
635 kwargs["parent_port_no"] = parentPort
636 onuDevice, err := dh.coreProxy.GetChildDevice(nil, dh.device.Id, kwargs)
637 if err != nil {
638 log.Errorw("onu not found", log.Fields{"intfId": parentPort, "onuId": onuId})
639 return nil
640 }
641 log.Debugw("Successfully received child device from core", log.Fields{"child_device": *onuDevice})
642 return onuDevice
manikkaraj kbf256be2019-03-25 00:13:48 +0530643}
644
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400645func (dh *DeviceHandler) SendPacketInToCore(logicalPort uint32, packetPayload []byte) {
646 log.Debugw("SendPacketInToCore", log.Fields{"port": logicalPort, "packetPayload": packetPayload})
647 if err := dh.coreProxy.SendPacketIn(nil, dh.device.Id, logicalPort, packetPayload); err != nil {
648 log.Errorw("Error sending packetin to core", log.Fields{"error": err})
649 return
650 }
651 log.Debug("Sent packet-in to core successfully")
652}
653
manikkaraj kbf256be2019-03-25 00:13:48 +0530654func (dh *DeviceHandler) UpdateFlowsIncrementally(device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges) error {
Girish Gowdru0c588b22019-04-23 23:24:56 -0400655 log.Debugw("In UpdateFlowsIncrementally", log.Fields{"deviceId": device.Id, "flows": flows, "groups": groups})
656 if flows != nil {
657 for _, flow := range flows.ToAdd.Items {
658 dh.flowMgr.AddFlow(flow)
659 }
660 }
661 if groups != nil {
662 for _, flow := range flows.ToRemove.Items {
663 log.Debug("Removing flow", log.Fields{"deviceId": device.Id, "flowToRemove": flow})
664 // dh.flowMgr.RemoveFlow(flow)
665 }
666 }
667 return nil
manikkaraj kbf256be2019-03-25 00:13:48 +0530668}
Girish Gowdru5ba46c92019-04-25 05:00:05 -0400669
670func (dh *DeviceHandler) DisableDevice(device *voltha.Device) error {
671 if _, err := dh.Client.DisableOlt(context.Background(), new(oop.Empty)); err != nil {
672 log.Errorw("Failed to disable olt ", log.Fields{"err": err})
673 return err
674 }
675 dh.lockDevice.Lock()
676 dh.adminState = "down"
677 dh.lockDevice.Unlock()
678 log.Debug("olt-disabled")
679
680 cloned := proto.Clone(device).(*voltha.Device)
681 // Update the all ports state on that device to disable
682 if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
683 log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
684 return err
685 }
686
687 //Update the device oper state
688 cloned.OperStatus = voltha.OperStatus_UNKNOWN
689 dh.device = cloned
690
691 if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
692 log.Errorw("error-updating-device-state", log.Fields{"deviceId": device.Id, "error": err})
693 return err
694 }
695 log.Debugw("DisableDevice-end", log.Fields{"deviceId": device.Id})
696 return nil
697}
698
699func (dh *DeviceHandler) ReenableDevice(device *voltha.Device) error {
700 if _, err := dh.Client.ReenableOlt(context.Background(), new(oop.Empty)); err != nil {
701 log.Errorw("Failed to reenable olt ", log.Fields{"err": err})
702 return err
703 }
704
705 dh.lockDevice.Lock()
706 dh.adminState = "up"
707 dh.lockDevice.Unlock()
708 log.Debug("olt-reenabled")
709
710 cloned := proto.Clone(device).(*voltha.Device)
711 // Update the all ports state on that device to enable
712 if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
713 log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
714 return err
715 }
716
717 //Update the device oper status as ACTIVE
718 cloned.OperStatus = voltha.OperStatus_ACTIVE
719 dh.device = cloned
720
721 if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
722 log.Errorw("error-updating-device-state", log.Fields{"deviceId": device.Id, "error": err})
723 return err
724 }
725 log.Debugw("ReEnableDevice-end", log.Fields{"deviceId": device.Id})
726
727 return nil
728}
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400729
730func (dh *DeviceHandler) handlePacketIndication(packetIn *oop.PacketIndication) {
731 log.Debugw("Received packet-in", log.Fields{"packet-indication": *packetIn})
732 logicalPortNum, err := dh.flowMgr.GetLogicalPortFromPacketIn(packetIn)
733 if err != nil {
734 log.Errorw("Error getting logical port from packet-in", log.Fields{"error": err})
735 return
736 }
737 log.Debugw("sending packet-in to core", log.Fields{"logicalPortNum": logicalPortNum, "packet": *packetIn})
738 if err := dh.coreProxy.SendPacketIn(nil, dh.device.Id, logicalPortNum, packetIn.Pkt); err != nil {
739 log.Errorw("Error sending packet-in to core", log.Fields{"error": err})
740 return
741 }
742 log.Debug("Success sending packet-in to core!")
743}
744
745func (dh *DeviceHandler) PacketOut(egress_port_no int, packet *of.OfpPacketOut) error {
746 log.Debugw("PacketOut", log.Fields{"deviceId": dh.deviceId, "egress_port_no": egress_port_no, "pkt-length": len(packet.Data)})
747 var etherFrame ethernet.Frame
748 err := (&etherFrame).UnmarshalBinary(packet.Data)
749 if err != nil {
750 log.Errorw("Failed to unmarshal into ethernet frame", log.Fields{"err": err, "pkt-length": len(packet.Data)})
751 return err
752 }
753 log.Debugw("Ethernet Frame", log.Fields{"Frame": etherFrame})
754 egressPortType := IntfIdToPortTypeName(uint32(egress_port_no))
755 if egressPortType == voltha.Port_ETHERNET_UNI {
756 if etherFrame.VLAN != nil { // If double tag, remove the outer tag
757 nextEthType := (uint16(packet.Data[16]) << 8) | uint16(packet.Data[17])
758 if nextEthType == 0x8100 {
759 etherFrame.VLAN = nil
760 packet.Data, err = etherFrame.MarshalBinary()
761 if err != nil {
762 log.Fatalf("failed to marshal frame: %v", err)
763 return err
764 }
765 if err := (&etherFrame).UnmarshalBinary(packet.Data); err != nil {
766 log.Fatalf("failed to unmarshal frame: %v", err)
767 return err
768 }
769 log.Debug("Double tagged packet , removed outer vlan", log.Fields{"New frame": etherFrame})
770 }
771 }
772 intfId := IntfIdFromUniPortNum(uint32(egress_port_no))
773 onuId := OnuIdFromPortNum(uint32(egress_port_no))
774 uniId := UniIdFromPortNum(uint32(egress_port_no))
775 /*gemPortId, err := dh.flowMgr.GetPacketOutGemPortId(intfId, onuId, uint32(egress_port_no))
776 if err != nil{
777 log.Errorw("Error while getting gemport to packet-out",log.Fields{"error": err})
778 return err
779 }*/
780 onuPkt := oop.OnuPacket{IntfId: intfId, OnuId: onuId, PortNo: uint32(egress_port_no), Pkt: packet.Data}
781 log.Debug("sending-packet-to-ONU", log.Fields{"egress_port_no": egress_port_no, "IntfId": intfId, "onuId": onuId,
782 "uniId": uniId, "packet": packet.Data})
783 if _, err := dh.Client.OnuPacketOut(context.Background(), &onuPkt); err != nil {
784 log.Errorw("Error while sending packet-out to ONU", log.Fields{"error": err})
785 return err
786 }
787 } else if egressPortType == voltha.Port_ETHERNET_NNI {
788 uplinkPkt := oop.UplinkPacket{IntfId: IntfIdFromNniPortNum(uint32(egress_port_no)), Pkt: packet.Data}
789 log.Debug("sending-packet-to-uplink", log.Fields{"uplink_pkt": uplinkPkt})
790 if _, err := dh.Client.UplinkPacketOut(context.Background(), &uplinkPkt); err != nil {
791 log.Errorw("Error while sending packet-out to uplink", log.Fields{"error": err})
792 return err
793 }
794 } else {
795 log.Warnw("Packet-out-to-this-interface-type-not-implemented", log.Fields{"egress_port_no": egress_port_no, "egressPortType": egressPortType})
796 }
797 return nil
798}