Restoring authRestart and dhcpRestart options

Change-Id: Ibeb26aa1cf4c6bfa984913edab1e51961c39522a
diff --git a/VERSION b/VERSION
index 13c0078..45a1b3f 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.1.2-dev
+1.1.2
diff --git a/internal/bbsim/devices/service_test.go b/internal/bbsim/devices/service_test.go
index a2b720d..548a14a 100644
--- a/internal/bbsim/devices/service_test.go
+++ b/internal/bbsim/devices/service_test.go
@@ -19,6 +19,7 @@
 import (
 	"context"
 	"github.com/opencord/bbsim/internal/bbsim/types"
+	"github.com/opencord/bbsim/internal/common"
 	"github.com/opencord/voltha-protos/v3/go/openolt"
 	"github.com/stretchr/testify/assert"
 	"net"
@@ -236,6 +237,13 @@
 // Test that if the EAPOL state machine doesn't complete in 30 seconds we
 // move it to EAPOL failed
 func TestService_EAPOLFailed(t *testing.T) {
+
+	common.Config = &common.GlobalConfig{
+		BBSim: common.BBSimConfig{
+			AuthRetry: false,
+		},
+	}
+
 	// override the default wait time
 	eapolWaitTime = 500 * time.Millisecond
 	s, err := createTestService(true, false)
@@ -261,9 +269,42 @@
 
 }
 
+func TestService_EAPOLRestart(t *testing.T) {
+
+	common.Config = &common.GlobalConfig{
+		BBSim: common.BBSimConfig{
+			AuthRetry: true,
+		},
+	}
+
+	eapolWaitTime = 500 * time.Millisecond
+	s, err := createTestService(true, false)
+
+	assert.Nil(t, err)
+
+	stream := &mockStream{
+		Calls: make(map[int]*openolt.Indication),
+	}
+	s.Initialize(stream)
+
+	// set to failed if timeout occurs
+	_ = s.EapolState.Event("start_auth")
+
+	// after a second EAPOL should have failed and restarted
+	time.Sleep(1 * time.Second)
+	assert.Equal(t, "eap_start_sent", s.EapolState.Current())
+}
+
 // Test that if the DHCP state machine doesn't complete in 30 seconds we
 // move it to DHCP failed
 func TestService_DHCPFailed(t *testing.T) {
+
+	common.Config = &common.GlobalConfig{
+		BBSim: common.BBSimConfig{
+			DhcpRetry: false,
+		},
+	}
+
 	// override the default wait time
 	dhcpWaitTime = 100 * time.Millisecond
 	s, err := createTestService(false, true)
@@ -287,3 +328,27 @@
 	time.Sleep(1 * time.Second)
 	assert.Equal(t, "dhcp_ack_received", s.DHCPState.Current())
 }
+
+func TestService_DHCPRestart(t *testing.T) {
+	common.Config = &common.GlobalConfig{
+		BBSim: common.BBSimConfig{
+			DhcpRetry: true,
+		},
+	}
+
+	// override the default wait time
+	dhcpWaitTime = 100 * time.Millisecond
+	s, err := createTestService(false, true)
+
+	assert.Nil(t, err)
+
+	stream := &mockStream{
+		Calls: make(map[int]*openolt.Indication),
+	}
+	s.Initialize(stream)
+
+	// set to failed if timeout occurs
+	_ = s.DHCPState.Event("start_dhcp")
+	time.Sleep(1 * time.Second)
+	assert.Equal(t, "dhcp_discovery_sent", s.DHCPState.Current())
+}
diff --git a/internal/bbsim/devices/services.go b/internal/bbsim/devices/services.go
index bfedd42..c7983a4 100644
--- a/internal/bbsim/devices/services.go
+++ b/internal/bbsim/devices/services.go
@@ -24,6 +24,7 @@
 	"github.com/opencord/bbsim/internal/bbsim/responders/eapol"
 	"github.com/opencord/bbsim/internal/bbsim/responders/igmp"
 	bbsimTypes "github.com/opencord/bbsim/internal/bbsim/types"
+	"github.com/opencord/bbsim/internal/common"
 	log "github.com/sirupsen/logrus"
 	"net"
 	"time"
@@ -174,7 +175,12 @@
 									"Name":       service.Name,
 									"EapolState": service.EapolState.Current(),
 								}).Warn("EAPOL failed, resetting EAPOL State")
+
 								_ = service.EapolState.Event("auth_failed")
+								if common.Config.BBSim.AuthRetry {
+									_ = service.EapolState.Event("start_auth")
+								}
+
 								return
 							}
 						}
@@ -223,7 +229,12 @@
 									"Name":      service.Name,
 									"DHCPState": service.DHCPState.Current(),
 								}).Warn("DHCP failed, resetting DHCP State")
+
 								_ = service.DHCPState.Event("dhcp_failed")
+								if common.Config.BBSim.DhcpRetry {
+									_ = service.DHCPState.Event("start_dhcp")
+								}
+
 								return
 							}
 						}