Cleanup

Change-Id: Iceb908751e93e7d42de5f06942092599b1a5509d
diff --git a/internal/bbsim/devices/messageTypes.go b/internal/bbsim/devices/messageTypes.go
new file mode 100644
index 0000000..6d3f076
--- /dev/null
+++ b/internal/bbsim/devices/messageTypes.go
@@ -0,0 +1,130 @@
+/*
+ * 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 devices
+
+import (
+	"github.com/google/gopacket"
+	"github.com/opencord/voltha-protos/go/openolt"
+)
+
+type MessageType int
+
+const (
+	OltIndication       MessageType = 0
+	NniIndication       MessageType = 1
+	PonIndication       MessageType = 2
+	OnuDiscIndication   MessageType = 3
+	OnuIndication       MessageType = 4
+	OMCI                MessageType = 5
+	FlowUpdate          MessageType = 6
+	StartEAPOL          MessageType = 7
+	StartDHCP           MessageType = 8
+	OnuPacketOut        MessageType = 9
+	DyingGaspIndication MessageType = 10
+)
+
+func (m MessageType) String() string {
+	names := [...]string{
+		"OltIndication",
+		"NniIndication",
+		"PonIndication",
+		"OnuDiscIndication",
+		"OnuIndication",
+		"OMCI",
+		"FlowUpdate",
+		"StartEAPOL",
+		"StartDHCP",
+		"OnuPacketOut",
+		"DyingGaspIndication",
+	}
+	return names[m]
+}
+
+type Message struct {
+	Type MessageType
+	Data interface{}
+}
+
+type OltIndicationMessage struct {
+	OperState OperState
+}
+
+type NniIndicationMessage struct {
+	OperState OperState
+	NniPortID uint32
+}
+
+type PonIndicationMessage struct {
+	OperState OperState
+	PonPortID uint32
+}
+
+type OnuDiscIndicationMessage struct {
+	OperState OperState
+	Onu       Onu
+}
+
+type OnuIndicationMessage struct {
+	OperState OperState
+	PonPortID uint32
+	OnuID     uint32
+	OnuSN     *openolt.SerialNumber
+}
+
+type OmciMessage struct {
+	OnuSN   *openolt.SerialNumber
+	OnuID   uint32
+	omciMsg *openolt.OmciMsg
+}
+
+type OnuFlowUpdateMessage struct {
+	PonPortID uint32
+	OnuID     uint32
+	Flow      *openolt.Flow
+}
+
+type PacketMessage struct {
+	PonPortID uint32
+	OnuID     uint32
+}
+
+type OnuPacketOutMessage struct {
+	IntfId uint32
+	OnuId  uint32
+	Packet gopacket.Packet
+}
+
+type DyingGaspIndicationMessage struct {
+	PonPortID uint32
+	OnuID     uint32
+	Status    string
+}
+
+type OperState int
+
+const (
+	UP   OperState = iota
+	DOWN           // The device has been discovered, but not yet activated
+)
+
+func (m OperState) String() string {
+	names := [...]string{
+		"up",
+		"down",
+	}
+	return names[m]
+}
diff --git a/internal/bbsim/devices/nni.go b/internal/bbsim/devices/nni.go
index 814c825..05585fc 100644
--- a/internal/bbsim/devices/nni.go
+++ b/internal/bbsim/devices/nni.go
@@ -34,6 +34,15 @@
 	dhcpServerIp = "182.21.0.128"
 )
 
+type NniPort struct {
+	// BBSIM Internals
+	ID uint32
+
+	// PON Attributes
+	OperState *fsm.FSM
+	Type      string
+}
+
 func CreateNNI(olt *OltDevice) (NniPort, error) {
 	nniPort := NniPort{
 		ID: uint32(0),
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index 33126a8..2d46ced 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -36,9 +36,24 @@
 	"module": "OLT",
 })
 
-func init() {
-	//log.SetReportCaller(true)
-	log.SetLevel(log.DebugLevel)
+type OltDevice struct {
+	// BBSIM Internals
+	ID              int
+	SerialNumber    string
+	NumNni          int
+	NumPon          int
+	NumOnuPerPon    int
+	InternalState   *fsm.FSM
+	channel         chan Message
+	oltDoneChannel  *chan bool
+	apiDoneChannel  *chan bool
+	nniPktInChannel chan *bbsim.PacketMsg
+
+	Pons []PonPort
+	Nnis []NniPort
+
+	// OLT Attributes
+	OperState *fsm.FSM
 }
 
 var olt = OltDevice{}
@@ -561,19 +576,6 @@
 	}
 	onu.Channel <- msg
 
-	//etherType := rawpkt.Layer(layers.LayerTypeEthernet).(*layers.Ethernet).EthernetType
-	//
-	//if etherType == layers.EthernetTypeEAPOL {
-	//	eapolPkt := bbsim.ByteMsg{IntfId: onuPkt.IntfId, OnuId: onuPkt.OnuId, Bytes: rawpkt.Data()}
-	//	onu.eapolPktOutCh <- &eapolPkt
-	//} else if layerDHCP := rawpkt.Layer(layers.LayerTypeDHCPv4); layerDHCP != nil {
-	//	// TODO use IsDhcpPacket
-	//	// TODO we need to untag the packets
-	//	// NOTE here we receive packets going from the DHCP Server to the ONU
-	//	// for now we expect them to be double-tagged, but ideally the should be single tagged
-	//	dhcpPkt := bbsim.ByteMsg{IntfId: onuPkt.IntfId, OnuId: onuPkt.OnuId, Bytes: rawpkt.Data()}
-	//	onu.dhcpPktOutCh <- &dhcpPkt
-	//}
 	return new(openolt.Empty), nil
 }
 
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index 3477a62..dfbd9ce 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -23,7 +23,6 @@
 	"github.com/opencord/bbsim/internal/bbsim/packetHandlers"
 	"github.com/opencord/bbsim/internal/bbsim/responders/dhcp"
 	"github.com/opencord/bbsim/internal/bbsim/responders/eapol"
-	bbsim "github.com/opencord/bbsim/internal/bbsim/types"
 	omci "github.com/opencord/omci-sim"
 	"github.com/opencord/voltha-protos/go/openolt"
 	log "github.com/sirupsen/logrus"
@@ -34,6 +33,25 @@
 	"module": "ONU",
 })
 
+type Onu struct {
+	ID            uint32
+	PonPortID     uint32
+	PonPort       PonPort
+	STag          int
+	CTag          int
+	HwAddress     net.HardwareAddr
+	InternalState *fsm.FSM
+
+	OperState    *fsm.FSM
+	SerialNumber *openolt.SerialNumber
+
+	Channel chan Message // this Channel is to track state changes OMCI messages, EAPOL and DHCP packets
+}
+
+func (o Onu) Sn() string {
+	return onuSnToString(o.SerialNumber)
+}
+
 func CreateONU(olt OltDevice, pon PonPort, id uint32, sTag int, cTag int) Onu {
 
 	o := Onu{
@@ -44,9 +62,7 @@
 		CTag:      cTag,
 		HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(pon.ID), byte(id)},
 		// NOTE can we combine everything in a single Channel?
-		Channel:       make(chan Message, 2048),
-		eapolPktOutCh: make(chan *bbsim.ByteMsg, 1024),
-		dhcpPktOutCh:  make(chan *bbsim.ByteMsg, 1024),
+		Channel: make(chan Message, 2048),
 	}
 	o.SerialNumber = o.NewSN(olt.ID, pon.ID, o.ID)
 
@@ -185,7 +201,7 @@
 			o.handleFlowUpdate(msg, stream)
 		case StartEAPOL:
 			log.Infof("Receive StartEAPOL message on ONU Channel")
-			eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.InternalState, stream)
+			eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.HwAddress, o.InternalState, stream)
 		case StartDHCP:
 			log.Infof("Receive StartDHCP message on ONU Channel")
 			dhcp.SendDHCPDiscovery(o.PonPortID, o.ID, o.Sn(), o.InternalState, o.HwAddress, o.CTag, stream)
diff --git a/internal/bbsim/devices/pon.go b/internal/bbsim/devices/pon.go
new file mode 100644
index 0000000..0e67e51
--- /dev/null
+++ b/internal/bbsim/devices/pon.go
@@ -0,0 +1,57 @@
+/*
+ * 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 devices
+
+import (
+	"bytes"
+	"errors"
+	"fmt"
+	"github.com/looplab/fsm"
+	"github.com/opencord/voltha-protos/go/openolt"
+)
+
+type PonPort struct {
+	// BBSIM Internals
+	ID     uint32
+	NumOnu int
+	Onus   []Onu
+	Olt    OltDevice
+
+	// PON Attributes
+	OperState *fsm.FSM
+	Type      string
+
+	// NOTE do we need a state machine for the PON Ports?
+}
+
+func (p PonPort) getOnuBySn(sn *openolt.SerialNumber) (*Onu, error) {
+	for _, onu := range p.Onus {
+		if bytes.Equal(onu.SerialNumber.VendorSpecific, sn.VendorSpecific) {
+			return &onu, nil
+		}
+	}
+	return nil, errors.New(fmt.Sprintf("Cannot find Onu with serial number %d in PonPort %d", sn, p.ID))
+}
+
+func (p PonPort) getOnuById(id uint32) (*Onu, error) {
+	for _, onu := range p.Onus {
+		if onu.ID == id {
+			return &onu, nil
+		}
+	}
+	return nil, errors.New(fmt.Sprintf("Cannot find Onu with id %d in PonPort %d", id, p.ID))
+}
diff --git a/internal/bbsim/devices/types.go b/internal/bbsim/devices/types.go
deleted file mode 100644
index eca15d4..0000000
--- a/internal/bbsim/devices/types.go
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * 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 devices
-
-import (
-	"bytes"
-	"errors"
-	"fmt"
-	"github.com/google/gopacket"
-	"github.com/looplab/fsm"
-	bbsim "github.com/opencord/bbsim/internal/bbsim/types"
-	"github.com/opencord/voltha-protos/go/openolt"
-	"net"
-)
-
-// TODO get rid of this file
-// - move ONU and OLT struct in their respective file
-// - create files for PonPorts and NniPorts
-// - move messages in the `types` package
-
-// Devices
-type Onu struct {
-	ID            uint32
-	PonPortID     uint32
-	PonPort       PonPort
-	STag          int
-	CTag          int
-	HwAddress     net.HardwareAddr
-	InternalState *fsm.FSM
-
-	OperState    *fsm.FSM
-	SerialNumber *openolt.SerialNumber
-
-	Channel       chan Message        // this Channel is to track state changes and OMCI messages
-	eapolPktOutCh chan *bbsim.ByteMsg // this Channel is for EAPOL Packet Outs (coming from the controller)
-	dhcpPktOutCh  chan *bbsim.ByteMsg // this Channel is for DHCP Packet Outs (coming from the controller)
-}
-
-func (o Onu) Sn() string {
-	return onuSnToString(o.SerialNumber)
-}
-
-type NniPort struct {
-	// BBSIM Internals
-	ID uint32
-
-	// PON Attributes
-	OperState *fsm.FSM
-	Type      string
-}
-
-type PonPort struct {
-	// BBSIM Internals
-	ID     uint32
-	NumOnu int
-	Onus   []Onu
-	Olt    OltDevice
-
-	// PON Attributes
-	OperState *fsm.FSM
-	Type      string
-
-	// NOTE do we need a state machine for the PON Ports?
-}
-
-func (p PonPort) getOnuBySn(sn *openolt.SerialNumber) (*Onu, error) {
-	for _, onu := range p.Onus {
-		if bytes.Equal(onu.SerialNumber.VendorSpecific, sn.VendorSpecific) {
-			return &onu, nil
-		}
-	}
-	return nil, errors.New(fmt.Sprintf("Cannot find Onu with serial number %d in PonPort %d", sn, p.ID))
-}
-
-func (p PonPort) getOnuById(id uint32) (*Onu, error) {
-	for _, onu := range p.Onus {
-		if onu.ID == id {
-			return &onu, nil
-		}
-	}
-	return nil, errors.New(fmt.Sprintf("Cannot find Onu with id %d in PonPort %d", id, p.ID))
-}
-
-type OltDevice struct {
-	// BBSIM Internals
-	ID              int
-	SerialNumber    string
-	NumNni          int
-	NumPon          int
-	NumOnuPerPon    int
-	InternalState   *fsm.FSM
-	channel         chan Message
-	oltDoneChannel  *chan bool
-	apiDoneChannel  *chan bool
-	nniPktInChannel chan *bbsim.PacketMsg
-
-	Pons []PonPort
-	Nnis []NniPort
-
-	// OLT Attributes
-	OperState *fsm.FSM
-}
-
-// BBSim Internals
-
-type MessageType int
-
-const (
-	OltIndication       MessageType = 0
-	NniIndication       MessageType = 1
-	PonIndication       MessageType = 2
-	OnuDiscIndication   MessageType = 3
-	OnuIndication       MessageType = 4
-	OMCI                MessageType = 5
-	FlowUpdate          MessageType = 6
-	StartEAPOL          MessageType = 7
-	StartDHCP           MessageType = 8
-	OnuPacketOut        MessageType = 9
-	DyingGaspIndication MessageType = 10
-)
-
-func (m MessageType) String() string {
-	names := [...]string{
-		"OltIndication",
-		"NniIndication",
-		"PonIndication",
-		"OnuDiscIndication",
-		"OnuIndication",
-		"OMCI",
-		"FlowUpdate",
-		"StartEAPOL",
-		"StartDHCP",
-		"OnuPacketOut",
-		"DyingGaspIndication",
-	}
-	return names[m]
-}
-
-type Message struct {
-	Type MessageType
-	Data interface{}
-}
-
-type OltIndicationMessage struct {
-	OperState OperState
-}
-
-type NniIndicationMessage struct {
-	OperState OperState
-	NniPortID uint32
-}
-
-type PonIndicationMessage struct {
-	OperState OperState
-	PonPortID uint32
-}
-
-type OnuDiscIndicationMessage struct {
-	OperState OperState
-	Onu       Onu
-}
-
-type OnuIndicationMessage struct {
-	OperState OperState
-	PonPortID uint32
-	OnuID     uint32
-	OnuSN     *openolt.SerialNumber
-}
-
-type OmciMessage struct {
-	OnuSN   *openolt.SerialNumber
-	OnuID   uint32
-	omciMsg *openolt.OmciMsg
-}
-
-type OnuFlowUpdateMessage struct {
-	PonPortID uint32
-	OnuID     uint32
-	Flow      *openolt.Flow
-}
-
-type PacketMessage struct {
-	PonPortID uint32
-	OnuID     uint32
-}
-
-type DyingGaspIndicationMessage struct {
-	PonPortID uint32
-	OnuID     uint32
-	Status    string
-}
-
-type OnuPacketOutMessage struct {
-	IntfId uint32
-	OnuId  uint32
-	Packet gopacket.Packet
-}
-
-type OperState int
-
-const (
-	UP   OperState = iota
-	DOWN           // The device has been discovered, but not yet activated
-)
-
-func (m OperState) String() string {
-	names := [...]string{
-		"up",
-		"down",
-	}
-	return names[m]
-}
diff --git a/internal/bbsim/responders/eapol/eapol.go b/internal/bbsim/responders/eapol/eapol.go
index da08cf5..6f2642e 100644
--- a/internal/bbsim/responders/eapol/eapol.go
+++ b/internal/bbsim/responders/eapol/eapol.go
@@ -129,7 +129,7 @@
 	return nil
 }
 
-func SendEapStart(onuId uint32, ponPortId uint32, serialNumber string, onuStateMachine *fsm.FSM, stream openolt.Openolt_EnableIndicationServer) error {
+func SendEapStart(onuId uint32, ponPortId uint32, serialNumber string, macAddress net.HardwareAddr, onuStateMachine *fsm.FSM, stream openolt.Openolt_EnableIndicationServer) error {
 
 	// send the packet (hacked together)
 	gemId, err := GetGemPortId(ponPortId, onuId)
@@ -151,7 +151,7 @@
 	options := gopacket.SerializeOptions{}
 
 	ethernetLayer := &layers.Ethernet{
-		SrcMAC:       net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(ponPortId), byte(onuId)}, // TODO move the SrcMAC in the ONU Device
+		SrcMAC:       macAddress,
 		DstMAC:       net.HardwareAddr{0x01, 0x80, 0xC2, 0x00, 0x00, 0x03},
 		EthernetType: layers.EthernetTypeEAPOL,
 	}
diff --git a/internal/bbsim/responders/eapol/eapol_test.go b/internal/bbsim/responders/eapol/eapol_test.go
index a3df56f..6a80317 100644
--- a/internal/bbsim/responders/eapol/eapol_test.go
+++ b/internal/bbsim/responders/eapol/eapol_test.go
@@ -22,6 +22,7 @@
 	"github.com/opencord/voltha-protos/go/openolt"
 	"google.golang.org/grpc"
 	"gotest.tools/assert"
+	"net"
 	"testing"
 )
 
@@ -77,9 +78,11 @@
 	var ponPortId uint32 = 0
 	var serialNumber string = "BBSM00000001"
 
+	var macAddress = net.HardwareAddr{0x01, 0x80, 0xC2, 0x00, 0x00, 0x03}
+
 	stream := mockStreamSuccess{}
 
-	if err := SendEapStart(onuId, ponPortId, serialNumber, eapolStateMachine, stream); err != nil {
+	if err := SendEapStart(onuId, ponPortId, serialNumber, macAddress, eapolStateMachine, stream); err != nil {
 		t.Errorf("SendEapStart returned an error: %v", err)
 		t.Fail()
 	}
@@ -107,9 +110,11 @@
 	var ponPortId uint32 = 0
 	var serialNumber string = "BBSM00000001"
 
+	var macAddress = net.HardwareAddr{0x01, 0x80, 0xC2, 0x00, 0x00, 0x03}
+
 	stream := mockStreamSuccess{}
 
-	err := SendEapStart(onuId, ponPortId, serialNumber, eapolStateMachine, stream)
+	err := SendEapStart(onuId, ponPortId, serialNumber, macAddress, eapolStateMachine, stream)
 	if err == nil {
 		t.Errorf("SendEapStart did not return an error")
 		t.Fail()
@@ -135,11 +140,12 @@
 	// params for the function under test
 	var onuId uint32 = 1
 	var ponPortId uint32 = 0
-	var serialNumber string = "BBSM00000001"
+	var serialNumber = "BBSM00000001"
+	var macAddress = net.HardwareAddr{0x01, 0x80, 0xC2, 0x00, 0x00, 0x03}
 
 	stream := mockStreamError{}
 
-	err := SendEapStart(onuId, ponPortId, serialNumber, eapolStateMachine, stream)
+	err := SendEapStart(onuId, ponPortId, serialNumber, macAddress, eapolStateMachine, stream)
 	if err == nil {
 		t.Errorf("SendEapStart did not return an error")
 		t.Fail()
diff --git a/internal/bbsim/types/types.go b/internal/bbsim/types/types.go
index 83f44fb..aa3740d 100644
--- a/internal/bbsim/types/types.go
+++ b/internal/bbsim/types/types.go
@@ -16,7 +16,9 @@
 
 package types
 
-import "github.com/google/gopacket"
+import (
+	"github.com/google/gopacket"
+)
 
 // deprecated
 type ByteMsg struct {
diff --git a/internal/bbsimctl/commands/olt.go b/internal/bbsimctl/commands/olt.go
index 3a434b2..fa847ff 100644
--- a/internal/bbsimctl/commands/olt.go
+++ b/internal/bbsimctl/commands/olt.go
@@ -40,7 +40,6 @@
 
 type OltPONs struct{}
 
-// TODO add autocomplete
 type oltOptions struct {
 	Get OltGet  `command:"get"`
 	NNI OltNNIs `command:"nnis"`
@@ -77,7 +76,6 @@
 	fmt.Println()
 }
 
-// TODO use voltctl or cordctl parser to print tables (this needs to be moved out of the internals package)
 func (o *OltGet) Execute(args []string) error {
 	olt := getOLT()
 
diff --git a/internal/bbsimctl/commands/onu.go b/internal/bbsimctl/commands/onu.go
index fc89300..8fe4ea8 100644
--- a/internal/bbsimctl/commands/onu.go
+++ b/internal/bbsimctl/commands/onu.go
@@ -181,7 +181,7 @@
 
 	onus, err := client.GetONUs(ctx, &pb.Empty{})
 	if err != nil {
-		log.Fatal("could not get ONUs: %v", err)
+		log.Fatalf("could not get ONUs: %v", err)
 		return nil
 	}