VOL-1868 move simulated onu from voltha-go to voltha-simonu-adapter

Sourced from voltha-go commit 251a11c0ffe60512318a644cd6ce0dc4e12f4018

Change-Id: Iab179bc2f3dd772ed7f488d1c03d1a84ba75e874
diff --git a/internal/pkg/adaptercore/device_handler.go b/internal/pkg/adaptercore/device_handler.go
new file mode 100644
index 0000000..fa41136
--- /dev/null
+++ b/internal/pkg/adaptercore/device_handler.go
@@ -0,0 +1,318 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package adaptercore
+
+import (
+	"context"
+	"fmt"
+	"github.com/gogo/protobuf/proto"
+	com "github.com/opencord/voltha-go/adapters/common"
+	"github.com/opencord/voltha-go/common/log"
+	ic "github.com/opencord/voltha-protos/go/inter_container"
+	of "github.com/opencord/voltha-protos/go/openflow_13"
+	"github.com/opencord/voltha-protos/go/voltha"
+	"strconv"
+	"strings"
+	"sync"
+	"time"
+)
+
+// A set of pm names to create the initial pm config.  This is used only for testing in this simulated adapter
+var pmNames = []string{
+	"tx_64_pkts",
+	"tx_65_127_pkts",
+	"tx_128_255_pkts",
+	"tx_1024_1518_pkts",
+	"tx_1519_9k_pkts",
+	"rx_64_pkts",
+	"rx_64_pkts",
+	"rx_65_127_pkts",
+	"rx_128_255_pkts",
+	"rx_1024_1518_pkts",
+	"rx_1519_9k_pkts",
+}
+
+//DeviceHandler follows the same patterns as ponsim_olt.  The only difference is that it does not
+// interact with an OLT device.
+type DeviceHandler struct {
+	deviceId     string
+	deviceType   string
+	device       *voltha.Device
+	coreProxy    *com.CoreProxy
+	simulatedOLT *SimulatedONU
+	uniPort      *voltha.Port
+	ponPort      *voltha.Port
+	exitChannel  chan int
+	lockDevice   sync.RWMutex
+	metrics      *com.PmMetrics
+}
+
+//NewDeviceHandler creates a new device handler
+func NewDeviceHandler(cp *com.CoreProxy, device *voltha.Device, adapter *SimulatedONU) *DeviceHandler {
+	var dh DeviceHandler
+	dh.coreProxy = cp
+	cloned := (proto.Clone(device)).(*voltha.Device)
+	dh.deviceId = cloned.Id
+	dh.deviceType = cloned.Type
+	dh.device = cloned
+	dh.simulatedOLT = adapter
+	dh.exitChannel = make(chan int, 1)
+	dh.lockDevice = sync.RWMutex{}
+	dh.metrics = com.NewPmMetrics(
+		cloned.Id,
+		com.Frequency(150),
+		com.Grouped(false),
+		com.FrequencyOverride(false),
+		com.Metrics(pmNames),
+	)
+	return &dh
+}
+
+// start save the device to the data model
+func (dh *DeviceHandler) start(ctx context.Context) {
+	dh.lockDevice.Lock()
+	defer dh.lockDevice.Unlock()
+	log.Debugw("starting-device-agent", log.Fields{"device": dh.device})
+	// Add the initial device to the local model
+	log.Debug("device-agent-started")
+}
+
+// stop stops the device dh.  Not much to do for now
+func (dh *DeviceHandler) stop(ctx context.Context) {
+	dh.lockDevice.Lock()
+	defer dh.lockDevice.Unlock()
+	log.Debug("stopping-device-agent")
+	dh.exitChannel <- 1
+	log.Debug("device-agent-stopped")
+}
+
+func macAddressToUint32Array(mac string) []uint32 {
+	slist := strings.Split(mac, ":")
+	result := make([]uint32, len(slist))
+	var err error
+	var tmp int64
+	for index, val := range slist {
+		if tmp, err = strconv.ParseInt(val, 16, 32); err != nil {
+			return []uint32{1, 2, 3, 4, 5, 6}
+		}
+		result[index] = uint32(tmp)
+	}
+	return result
+}
+
+func (dh *DeviceHandler) AdoptDevice(device *voltha.Device) {
+	log.Debugw("AdoptDevice", log.Fields{"deviceId": device.Id})
+
+	//	Update the device info
+	cloned := proto.Clone(device).(*voltha.Device)
+	cloned.Root = false
+	cloned.Vendor = "simulators"
+	cloned.Model = "go-simulators"
+	//cloned.SerialNumber = com.GetRandomSerialNumber()
+	cloned.MacAddress = strings.ToUpper(com.GetRandomMacAddress())
+
+	// Synchronous call to update device - this method is run in its own go routine
+	if err := dh.coreProxy.DeviceUpdate(nil, cloned); err != nil {
+		log.Errorw("error-updating-device", log.Fields{"deviceId": device.Id, "error": err})
+	}
+
+	//	Update the device state to DISCOVERED
+	cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE
+	cloned.OperStatus = voltha.OperStatus_DISCOVERED
+	if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+		log.Errorw("error-creating-nni-port", log.Fields{"deviceId": device.Id, "error": err})
+	}
+
+	// Now, set the initial PM configuration for that device
+	if err := dh.coreProxy.DevicePMConfigUpdate(nil, dh.metrics.ToPmConfigs()); err != nil {
+		log.Errorw("error-updating-PMs", log.Fields{"deviceId": device.Id, "error": err})
+	}
+
+	// Sleep to mimic the omci management channel creation with the OLT
+	time.Sleep(10 * time.Millisecond)
+
+	//	Update the device state to ACTIVATING
+	cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE
+	cloned.OperStatus = voltha.OperStatus_ACTIVATING
+	if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+		log.Errorw("error-creating-nni-port", log.Fields{"deviceId": device.Id, "error": err})
+	}
+
+	// Sleep to mimic the omci discovery ( usually takes a few seconds but for ease of simulated environment we are
+	// setting it to 100ms only.
+	time.Sleep(100 * time.Millisecond)
+
+	// Use the channel Id, assigned by the parent device to me, as the port number
+	uni_port := uint32(2)
+	if device.ProxyAddress != nil {
+		if device.ProxyAddress.ChannelId != 0 {
+			uni_port = device.ProxyAddress.ChannelId
+		}
+	}
+
+	//	Now create the UNI Port
+	dh.uniPort = &voltha.Port{
+		PortNo:     uni_port,
+		Label:      fmt.Sprintf("uni-%d", uni_port),
+		Type:       voltha.Port_ETHERNET_UNI,
+		AdminState: voltha.AdminState_ENABLED,
+		OperStatus: voltha.OperStatus_ACTIVE,
+	}
+
+	// Synchronous call to update device - this method is run in its own go routine
+	if err := dh.coreProxy.PortCreated(nil, cloned.Id, dh.uniPort); err != nil {
+		log.Errorw("error-creating-nni-port", log.Fields{"deviceId": device.Id, "error": err})
+	}
+	// use Pon port number on which this ONU has been detected
+	ponPortNo := uint32(1)
+	if device.ParentPortNo != 0 {
+		ponPortNo = device.ParentPortNo
+	}
+	//	Now create the PON Port
+	dh.ponPort = &voltha.Port{
+		PortNo:     ponPortNo,
+		Label:      fmt.Sprintf("pon-%d", ponPortNo),
+		Type:       voltha.Port_PON_ONU,
+		AdminState: voltha.AdminState_ENABLED,
+		OperStatus: voltha.OperStatus_ACTIVE,
+		Peers: []*voltha.Port_PeerPort{{DeviceId: cloned.ParentId, // Peer device  is OLT
+			PortNo: uni_port}}, // Peer port is UNI port
+	}
+
+	// Synchronous call to update device - this method is run in its own go routine
+	if err := dh.coreProxy.PortCreated(nil, cloned.Id, dh.ponPort); err != nil {
+		log.Errorw("error-creating-nni-port", log.Fields{"deviceId": device.Id, "error": err})
+	}
+
+	cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE
+	cloned.OperStatus = voltha.OperStatus_ACTIVE
+
+	//	Update the device state
+	if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+		log.Errorw("error-creating-nni-port", log.Fields{"deviceId": device.Id, "error": err})
+	}
+
+	dh.device = cloned
+}
+
+func (dh *DeviceHandler) GetOfpPortInfo(device *voltha.Device, portNo int64) (*ic.PortCapability, error) {
+	cap := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
+	return &ic.PortCapability{
+		Port: &voltha.LogicalPort{
+			OfpPort: &of.OfpPort{
+				HwAddr:     macAddressToUint32Array(dh.device.MacAddress),
+				Config:     0,
+				State:      uint32(of.OfpPortState_OFPPS_LIVE),
+				Curr:       cap,
+				Advertised: cap,
+				Peer:       cap,
+				CurrSpeed:  uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
+				MaxSpeed:   uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
+			},
+			DeviceId:     dh.device.Id,
+			DevicePortNo: uint32(portNo),
+		},
+	}, nil
+}
+
+func (dh *DeviceHandler) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
+	log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
+	return nil
+}
+
+func (dh *DeviceHandler) DisableDevice(device *voltha.Device) {
+	cloned := proto.Clone(device).(*voltha.Device)
+	// Update the all ports state on that device to disable
+	if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
+		log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+		return
+	}
+
+	//Update the device state
+	cloned.ConnectStatus = voltha.ConnectStatus_UNREACHABLE
+	cloned.OperStatus = voltha.OperStatus_UNKNOWN
+	dh.device = cloned
+
+	if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+		log.Errorw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+		return
+	}
+	log.Debugw("DisableDevice-end", log.Fields{"deviceId": device.Id})
+}
+
+func (dh *DeviceHandler) ReEnableDevice(device *voltha.Device) {
+
+	cloned := proto.Clone(device).(*voltha.Device)
+	// Update the all ports state on that device to enable
+	if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
+		log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+		return
+	}
+
+	//Update the device state
+	cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE
+	cloned.OperStatus = voltha.OperStatus_ACTIVE
+	dh.device = cloned
+
+	if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+		log.Errorw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+		return
+	}
+	log.Debugw("ReEnableDevice-end", log.Fields{"deviceId": device.Id})
+}
+
+func (dh *DeviceHandler) DeleteDevice(device *voltha.Device) {
+	cloned := proto.Clone(device).(*voltha.Device)
+	// Update the all ports state on that device to disable
+	if err := dh.coreProxy.DeleteAllPorts(nil, cloned.Id); err != nil {
+		log.Errorw("delete-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+		return
+	}
+
+	log.Debugw("DeleteDevice-end", log.Fields{"deviceId": device.Id})
+}
+
+func (dh *DeviceHandler) UpdateFlowsBulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, metadata *voltha.FlowMetadata) {
+	log.Debugw("UpdateFlowsBulk", log.Fields{"deviceId": device.Id, "flows": flows, "groups": groups})
+	// For now we do nothing with it
+	return
+}
+
+func (dh *DeviceHandler) UpdateFlowsIncremental(device *voltha.Device, flowChanges *of.FlowChanges, groupChanges *of.FlowGroupChanges, metadata *voltha.FlowMetadata) {
+	log.Debugw("UpdateFlowsIncremental", log.Fields{"deviceId": device.Id, "flowChanges": flowChanges, "groupChanges": groupChanges})
+	// For now we do nothing with it
+	return
+}
+
+func (dh *DeviceHandler) UpdatePmConfigs(device *voltha.Device, pmConfigs *voltha.PmConfigs) {
+	log.Debugw("UpdatePmConfigs", log.Fields{"deviceId": device.Id, "pmConfigs": pmConfigs})
+	// For now we do nothing with it
+	return
+}
+
+func (dh *DeviceHandler) ReconcileDevice(device *voltha.Device) {
+	// Update the device info
+	cloned := proto.Clone(device).(*voltha.Device)
+	cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE
+	cloned.OperStatus = voltha.OperStatus_ACTIVE
+
+	dh.device = cloned
+
+	// Update the device state
+	if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+		log.Errorw("error-creating-nni-port", log.Fields{"deviceId": device.Id, "error": err})
+	}
+}
diff --git a/internal/pkg/adaptercore/device_handler_test.go b/internal/pkg/adaptercore/device_handler_test.go
new file mode 100755
index 0000000..712a1ad
--- /dev/null
+++ b/internal/pkg/adaptercore/device_handler_test.go
@@ -0,0 +1,26 @@
+/*

+ * Copyright 2019-present Open Networking Foundation

+ *

+ * Licensed under the Apache License, Version 2.0 (the "License");

+ * you may not use this file except in compliance with the License.

+ * You may obtain a copy of the License at

+ *

+ * http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+package adaptercore

+

+import (

+	"github.com/stretchr/testify/assert"

+	"testing"

+)

+

+func TestMacAddressToUint32Array(t *testing.T) {

+	macArray := macAddressToUint32Array("12:34:56:78:90:AB")

+	assert.Equal(t, []uint32{0x12, 0x34, 0x56, 0x78, 0x90, 0xAB}, macArray)

+}

diff --git a/internal/pkg/adaptercore/simulated_onu.go b/internal/pkg/adaptercore/simulated_onu.go
new file mode 100644
index 0000000..bb23acf
--- /dev/null
+++ b/internal/pkg/adaptercore/simulated_onu.go
@@ -0,0 +1,293 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package adaptercore
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	com "github.com/opencord/voltha-go/adapters/common"
+	"github.com/opencord/voltha-go/common/log"
+	"github.com/opencord/voltha-go/kafka"
+	ic "github.com/opencord/voltha-protos/go/inter_container"
+	"github.com/opencord/voltha-protos/go/openflow_13"
+	"github.com/opencord/voltha-protos/go/voltha"
+	"sync"
+)
+
+type SimulatedONU struct {
+	deviceHandlers        map[string]*DeviceHandler
+	coreProxy             *com.CoreProxy
+	kafkaICProxy          *kafka.InterContainerProxy
+	exitChannel           chan int
+	lockDeviceHandlersMap sync.RWMutex
+}
+
+func NewSimulatedONU(ctx context.Context, kafkaICProxy *kafka.InterContainerProxy, coreProxy *com.CoreProxy) *SimulatedONU {
+	var simulatedOLT SimulatedONU
+	simulatedOLT.exitChannel = make(chan int, 1)
+	simulatedOLT.deviceHandlers = make(map[string]*DeviceHandler)
+	simulatedOLT.kafkaICProxy = kafkaICProxy
+	simulatedOLT.coreProxy = coreProxy
+	simulatedOLT.lockDeviceHandlersMap = sync.RWMutex{}
+	return &simulatedOLT
+}
+
+func (so *SimulatedONU) Start(ctx context.Context) error {
+	log.Info("starting-device-manager")
+	log.Info("device-manager-started")
+	return nil
+}
+
+func (so *SimulatedONU) Stop(ctx context.Context) error {
+	log.Info("stopping-device-manager")
+	so.exitChannel <- 1
+	log.Info("device-manager-stopped")
+	return nil
+}
+
+func sendResponse(ctx context.Context, ch chan interface{}, result interface{}) {
+	if ctx.Err() == nil {
+		// Returned response only of the ctx has not been cancelled/timeout/etc
+		// Channel is automatically closed when a context is Done
+		ch <- result
+		log.Debugw("sendResponse", log.Fields{"result": result})
+	} else {
+		// Should the transaction be reverted back?
+		log.Debugw("sendResponse-context-error", log.Fields{"context-error": ctx.Err()})
+	}
+}
+
+func (so *SimulatedONU) addDeviceHandlerToMap(agent *DeviceHandler) {
+	so.lockDeviceHandlersMap.Lock()
+	defer so.lockDeviceHandlersMap.Unlock()
+	if _, exist := so.deviceHandlers[agent.deviceId]; !exist {
+		so.deviceHandlers[agent.deviceId] = agent
+	}
+}
+
+func (so *SimulatedONU) deleteDeviceHandlerToMap(agent *DeviceHandler) {
+	so.lockDeviceHandlersMap.Lock()
+	defer so.lockDeviceHandlersMap.Unlock()
+	delete(so.deviceHandlers, agent.deviceId)
+}
+
+func (so *SimulatedONU) getDeviceHandler(deviceId string) *DeviceHandler {
+	so.lockDeviceHandlersMap.Lock()
+	defer so.lockDeviceHandlersMap.Unlock()
+	if agent, ok := so.deviceHandlers[deviceId]; ok {
+		return agent
+	}
+	return nil
+}
+
+func (so *SimulatedONU) Adopt_device(device *voltha.Device) error {
+	if device == nil {
+		log.Warn("device-is-nil")
+		return errors.New("nil-device")
+	}
+	log.Infow("adopt-device", log.Fields{"deviceId": device.Id})
+	var handler *DeviceHandler
+	if handler = so.getDeviceHandler(device.Id); handler == nil {
+		handler := NewDeviceHandler(so.coreProxy, device, so)
+		so.addDeviceHandlerToMap(handler)
+		go handler.AdoptDevice(device)
+	}
+	return nil
+}
+
+func (so *SimulatedONU) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) {
+	log.Infow("not-implemented-for-onu", log.Fields{"deviceId": device.Id})
+	return nil, nil
+}
+
+func (so *SimulatedONU) Get_ofp_port_info(device *voltha.Device, port_no int64) (*ic.PortCapability, error) {
+	log.Infow("Get_ofp_port_info", log.Fields{"deviceId": device.Id})
+	if handler := so.getDeviceHandler(device.Id); handler != nil {
+		return handler.GetOfpPortInfo(device, port_no)
+	}
+	log.Errorw("device-handler-not-set", log.Fields{"deviceId": device.Id})
+	return nil, errors.New("device-handler-not-set")
+}
+
+func (so *SimulatedONU) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error {
+	log.Infow("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
+	targetDevice := msg.Header.ProxyDeviceId // Request?
+	if targetDevice == "" && msg.Header.ToDeviceId != "" {
+		// Typical response
+		targetDevice = msg.Header.ToDeviceId
+	}
+	if handler := so.getDeviceHandler(targetDevice); handler != nil {
+		return handler.Process_inter_adapter_message(msg)
+	}
+	return errors.New(fmt.Sprintf("handler-not-found-%s", targetDevice))
+}
+
+func (so *SimulatedONU) Adapter_descriptor() error {
+	return errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Device_types() (*voltha.DeviceTypes, error) {
+	return nil, errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Health() (*voltha.HealthStatus, error) {
+	return nil, errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Reconcile_device(device *voltha.Device) error {
+	if device == nil {
+		log.Warn("device-is-nil")
+		return errors.New("nil-device")
+	}
+	log.Infow("reconcile-device", log.Fields{"deviceId": device.Id})
+	var handler *DeviceHandler
+	handler = so.getDeviceHandler(device.Id)
+	if handler == nil {
+		//	Adapter has restarted
+		handler = NewDeviceHandler(so.coreProxy, device, so)
+		so.addDeviceHandlerToMap(handler)
+	}
+	go handler.ReconcileDevice(device)
+
+	return nil
+}
+
+func (so *SimulatedONU) Abandon_device(device *voltha.Device) error {
+	return errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Disable_device(device *voltha.Device) error {
+	if device == nil {
+		log.Warn("device-is-nil")
+		return errors.New("nil-device")
+	}
+	log.Infow("disable-device", log.Fields{"deviceId": device.Id})
+	var handler *DeviceHandler
+	if handler = so.getDeviceHandler(device.Id); handler != nil {
+		go handler.DisableDevice(device)
+	}
+	return nil
+}
+
+func (so *SimulatedONU) Reenable_device(device *voltha.Device) error {
+	if device == nil {
+		log.Warn("device-is-nil")
+		return errors.New("nil-device")
+	}
+	log.Infow("reenable-device", log.Fields{"deviceId": device.Id})
+	var handler *DeviceHandler
+	if handler = so.getDeviceHandler(device.Id); handler != nil {
+		go handler.ReEnableDevice(device)
+	}
+	return nil
+}
+
+func (so *SimulatedONU) Reboot_device(device *voltha.Device) error {
+	return errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Self_test_device(device *voltha.Device) error {
+	return errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Delete_device(device *voltha.Device) error {
+	if device == nil {
+		log.Warn("device-is-nil")
+		return errors.New("nil-device")
+	}
+	log.Infow("delete-device", log.Fields{"deviceId": device.Id})
+	var handler *DeviceHandler
+	if handler = so.getDeviceHandler(device.Id); handler != nil {
+		go handler.DeleteDevice(device)
+	}
+	return nil
+}
+
+func (so *SimulatedONU) Get_device_details(device *voltha.Device) error {
+	return errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, metadata *voltha.FlowMetadata) error {
+	if device == nil {
+		log.Warn("device-is-nil")
+		return errors.New("nil-device")
+	}
+	log.Debugw("bulk-flow-updates", log.Fields{"deviceId": device.Id, "flows": flows, "groups": groups})
+	var handler *DeviceHandler
+	if handler = so.getDeviceHandler(device.Id); handler != nil {
+		go handler.UpdateFlowsBulk(device, flows, groups, metadata)
+	}
+	return nil
+}
+
+func (so *SimulatedONU) Update_flows_incrementally(device *voltha.Device, flowChanges *openflow_13.FlowChanges, groupChanges *openflow_13.FlowGroupChanges, metadata *voltha.FlowMetadata) error {
+	if device == nil {
+		log.Warn("device-is-nil")
+		return errors.New("nil-device")
+	}
+	log.Debugw("incremental-flow-update", log.Fields{"deviceId": device.Id, "flowChanges": flowChanges, "groupChanges": groupChanges})
+	var handler *DeviceHandler
+	if handler = so.getDeviceHandler(device.Id); handler != nil {
+		go handler.UpdateFlowsIncremental(device, flowChanges, groupChanges, metadata)
+	}
+	return nil
+}
+
+func (so *SimulatedONU) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error {
+	if device == nil {
+		log.Warn("device-is-nil")
+		return errors.New("nil-device")
+	}
+	log.Debugw("update_pm_config", log.Fields{"deviceId": device.Id, "pmConfigs": pmConfigs})
+	var handler *DeviceHandler
+	if handler = so.getDeviceHandler(device.Id); handler != nil {
+		go handler.UpdatePmConfigs(device, pmConfigs)
+	}
+	return nil
+}
+
+func (so *SimulatedONU) Receive_packet_out(deviceId string, egress_port_no int, msg *openflow_13.OfpPacketOut) error {
+	return errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Suppress_alarm(filter *voltha.AlarmFilter) error {
+	return errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Unsuppress_alarm(filter *voltha.AlarmFilter) error {
+	return errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
+	return nil, errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
+	return nil, errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
+	return nil, errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
+	return nil, errors.New("UnImplemented")
+}
+
+func (so *SimulatedONU) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) {
+	return nil, errors.New("UnImplemented")
+}
diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go
new file mode 100644
index 0000000..2971169
--- /dev/null
+++ b/internal/pkg/config/config.go
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package config
+
+import (
+	"flag"
+	"fmt"
+	"github.com/opencord/voltha-go/common/log"
+	"os"
+)
+
+// Simulated OLT default constants
+const (
+	EtcdStoreName            = "etcd"
+	default_InstanceID       = "simulatedOnu001"
+	default_KafkaAdapterHost = "127.0.0.1"
+	default_KafkaAdapterPort = 9092
+	default_KafkaClusterHost = "127.0.0.1"
+	default_KafkaClusterPort = 9094
+	default_KVStoreType      = EtcdStoreName
+	default_KVStoreTimeout   = 5 //in seconds
+	default_KVStoreHost      = "127.0.0.1"
+	default_KVStorePort      = 2379 // Consul = 8500; Etcd = 2379
+	default_LogLevel         = 0
+	default_Banner           = false
+	default_Topic            = "simulated_onu"
+	default_CoreTopic        = "rwcore"
+)
+
+// AdapterFlags represents the set of configurations used by the read-write adaptercore service
+type AdapterFlags struct {
+	// Command line parameters
+	InstanceID       string
+	KafkaAdapterHost string
+	KafkaAdapterPort int
+	KafkaClusterHost string
+	KafkaClusterPort int
+	KVStoreType      string
+	KVStoreTimeout   int // in seconds
+	KVStoreHost      string
+	KVStorePort      int
+	Topic            string
+	CoreTopic        string
+	LogLevel         int
+	Banner           bool
+}
+
+func init() {
+	log.AddPackage(log.JSON, log.WarnLevel, nil)
+}
+
+// NewRWCoreFlags returns a new RWCore config
+func NewAdapterFlags() *AdapterFlags {
+	var adapterFlags = AdapterFlags{ // Default values
+		InstanceID:       default_InstanceID,
+		KafkaAdapterHost: default_KafkaAdapterHost,
+		KafkaAdapterPort: default_KafkaAdapterPort,
+		KafkaClusterHost: default_KafkaClusterHost,
+		KafkaClusterPort: default_KafkaClusterPort,
+		KVStoreType:      default_KVStoreType,
+		KVStoreTimeout:   default_KVStoreTimeout,
+		KVStoreHost:      default_KVStoreHost,
+		KVStorePort:      default_KVStorePort,
+		Topic:            default_Topic,
+		CoreTopic:        default_CoreTopic,
+		LogLevel:         default_LogLevel,
+		Banner:           default_Banner,
+	}
+	return &adapterFlags
+}
+
+// ParseCommandArguments parses the arguments when running read-write adaptercore service
+func (so *AdapterFlags) ParseCommandArguments() {
+
+	var help string
+
+	help = fmt.Sprintf("Kafka - Adapter messaging host")
+	flag.StringVar(&(so.KafkaAdapterHost), "kafka_adapter_host", default_KafkaAdapterHost, help)
+
+	help = fmt.Sprintf("Kafka - Adapter messaging port")
+	flag.IntVar(&(so.KafkaAdapterPort), "kafka_adapter_port", default_KafkaAdapterPort, help)
+
+	help = fmt.Sprintf("Kafka - Cluster messaging host")
+	flag.StringVar(&(so.KafkaClusterHost), "kafka_cluster_host", default_KafkaClusterHost, help)
+
+	help = fmt.Sprintf("Kafka - Cluster messaging port")
+	flag.IntVar(&(so.KafkaClusterPort), "kafka_cluster_port", default_KafkaClusterPort, help)
+
+	help = fmt.Sprintf("Simulated ONU topic")
+	flag.StringVar(&(so.Topic), "simulator_topic", default_Topic, help)
+
+	help = fmt.Sprintf("Core topic")
+	flag.StringVar(&(so.CoreTopic), "core_topic", default_CoreTopic, help)
+
+	help = fmt.Sprintf("KV store type")
+	flag.StringVar(&(so.KVStoreType), "kv_store_type", default_KVStoreType, help)
+
+	help = fmt.Sprintf("The default timeout when making a kv store request")
+	flag.IntVar(&(so.KVStoreTimeout), "kv_store_request_timeout", default_KVStoreTimeout, help)
+
+	help = fmt.Sprintf("KV store host")
+	flag.StringVar(&(so.KVStoreHost), "kv_store_host", default_KVStoreHost, help)
+
+	help = fmt.Sprintf("KV store port")
+	flag.IntVar(&(so.KVStorePort), "kv_store_port", default_KVStorePort, help)
+
+	help = fmt.Sprintf("Log level")
+	flag.IntVar(&(so.LogLevel), "log_level", default_LogLevel, help)
+
+	help = fmt.Sprintf("Show startup banner log lines")
+	flag.BoolVar(&so.Banner, "banner", default_Banner, help)
+
+	flag.Parse()
+
+	containerName := getContainerInfo()
+	if len(containerName) > 0 {
+		so.InstanceID = containerName
+	}
+
+}
+
+func getContainerInfo() string {
+	return os.Getenv("HOSTNAME")
+}