Cleaning up the ONU state when disabling the device

Change-Id: Ie88f58b52a5ea27409c1be0f64fc99a0551b0f7b
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index f385a45..a62d240 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -64,7 +64,7 @@
 	// ONU State
 	// PortNo comes with flows and it's used when sending packetIndications,
 	// There is one PortNo per UNI Port, for now we're only storing the first one
-	// FIXME add support for multiple UNIs
+	// FIXME add support for multiple UNIs (each UNI has a different PortNo)
 	PortNo           uint32
 	DhcpFlowReceived bool
 	Flows            []FlowKey
@@ -199,6 +199,13 @@
 				o.Channel <- msg
 			},
 			"enter_disabled": func(event *fsm.Event) {
+
+				// clean the ONU state
+				o.DhcpFlowReceived = false
+				o.PortNo = 0
+				o.Flows = []FlowKey{}
+
+				// set the OpenState to disabled
 				if err := o.OperState.Event("disable"); err != nil {
 					onuLogger.WithFields(log.Fields{
 						"OnuId":  o.ID,
@@ -206,6 +213,8 @@
 						"OnuSn":  o.Sn(),
 					}).Errorf("Cannot change ONU OperState to down: %s", err.Error())
 				}
+
+				// send the OnuIndication DOWN event
 				msg := Message{
 					Type: OnuIndication,
 					Data: OnuIndicationMessage{
diff --git a/internal/bbsim/devices/onu_state_machine_test.go b/internal/bbsim/devices/onu_state_machine_test.go
index 4ceded9..0bf4bed 100644
--- a/internal/bbsim/devices/onu_state_machine_test.go
+++ b/internal/bbsim/devices/onu_state_machine_test.go
@@ -31,6 +31,26 @@
 	assert.Equal(t, onu.InternalState.Current(), "enabled")
 }
 
+func Test_Onu_StateMachine_disable(t *testing.T) {
+	onu := createTestOnu()
+	onu.InternalState.SetState("enabled")
+	assert.Equal(t, onu.InternalState.Current(), "enabled")
+
+	onu.PortNo = 16
+	onu.DhcpFlowReceived = true
+	onu.Flows = []FlowKey{
+		FlowKey{ID:1, Direction:"upstream"},
+		FlowKey{ID:2, Direction:"downstream"},
+	}
+
+	onu.InternalState.Event("disable")
+	assert.Equal(t, onu.InternalState.Current(), "disabled")
+
+	assert.Equal(t, onu.DhcpFlowReceived, false)
+	assert.Equal(t, onu.PortNo, uint32(0))
+	assert.Equal(t, len(onu.Flows), 0)
+}
+
 func Test_Onu_StateMachine_eapol_start_eap_flow(t *testing.T) {
 	onu := createTestOnu()