[VOL-2176] Adding -no-auth and -no-dhcp option in BBSim CLI
Change-Id: I3d0f7adb26c1df0d42f67b9b8fbc782754491c31
diff --git a/internal/bbsim/devices/onu_flow_test.go b/internal/bbsim/devices/onu_flow_test.go
index 4194aa5..fad206c 100644
--- a/internal/bbsim/devices/onu_flow_test.go
+++ b/internal/bbsim/devices/onu_flow_test.go
@@ -25,7 +25,7 @@
)
func Test_Onu_SendEapolFlow(t *testing.T) {
- onu := createMockOnu(1, 1, 900, 900)
+ onu := createMockOnu(1, 1, 900, 900, false, false)
client := &mockClient{
FlowAddSpy: FlowAddSpy{
@@ -49,7 +49,7 @@
// it transition to auth_started state
func Test_HandleFlowUpdateEapolFromGem(t *testing.T) {
- onu := createMockOnu(1, 1, 900, 900)
+ onu := createMockOnu(1, 1, 900, 900, true, false)
onu.InternalState = fsm.NewFSM(
"gem_port_added",
@@ -90,7 +90,7 @@
// no action is taken
func Test_HandleFlowUpdateEapolFromGemIgnore(t *testing.T) {
- onu := createMockOnu(1, 1, 900, 900)
+ onu := createMockOnu(1, 1, 900, 900, false, false)
onu.InternalState = fsm.NewFSM(
"gem_port_added",
@@ -131,7 +131,7 @@
// it transition to auth_started state
func Test_HandleFlowUpdateEapolFromEnabled(t *testing.T) {
- onu := createMockOnu(1, 1, 900, 900)
+ onu := createMockOnu(1, 1, 900, 900, false, false)
onu.InternalState = fsm.NewFSM(
"enabled",
@@ -172,7 +172,7 @@
// no action is taken
func Test_HandleFlowUpdateEapolFromEnabledIgnore(t *testing.T) {
- onu := createMockOnu(1, 1, 900, 900)
+ onu := createMockOnu(1, 1, 900, 900, false, false)
onu.InternalState = fsm.NewFSM(
"enabled",
@@ -209,4 +209,122 @@
assert.Equal(t, onu.InternalState.Current(), "enabled")
}
-// TODO add tests for DHCP flow
+// validates that when an ONU receives an EAPOL flow for UNI 0
+// but the noAuth bit is set no action is taken
+func Test_HandleFlowUpdateEapolNoAuth(t *testing.T) {
+ onu := createMockOnu(1, 1, 900, 900, false, false)
+
+ onu.InternalState = fsm.NewFSM(
+ "gem_port_added",
+ fsm.Events{
+ {Name: "start_auth", Src: []string{"eapol_flow_received", "gem_port_added"}, Dst: "auth_started"},
+ },
+ fsm.Callbacks{},
+ )
+
+ flow := openolt.Flow{
+ AccessIntfId: int32(onu.PonPortID),
+ OnuId: int32(onu.ID),
+ UniId: int32(0),
+ FlowId: uint32(onu.ID),
+ FlowType: "downstream",
+ AllocId: int32(0),
+ NetworkIntfId: int32(0),
+ Classifier: &openolt.Classifier{
+ EthType: uint32(layers.EthernetTypeEAPOL),
+ OVid: 4091,
+ },
+ Action: &openolt.Action{},
+ Priority: int32(100),
+ PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
+ }
+
+ msg := OnuFlowUpdateMessage{
+ PonPortID: 1,
+ OnuID: 1,
+ Flow: &flow,
+ }
+
+ onu.handleFlowUpdate(msg)
+ assert.Equal(t, onu.InternalState.Current(), "gem_port_added")
+}
+
+func Test_HandleFlowUpdateDhcp(t *testing.T) {
+ onu := createMockOnu(1, 1, 900, 900, false, true)
+
+ onu.InternalState = fsm.NewFSM(
+ "eap_response_success_received",
+ fsm.Events{
+ {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"},
+ },
+ fsm.Callbacks{},
+ )
+
+ flow := openolt.Flow{
+ AccessIntfId: int32(onu.PonPortID),
+ OnuId: int32(onu.ID),
+ UniId: int32(0),
+ FlowId: uint32(onu.ID),
+ FlowType: "downstream",
+ AllocId: int32(0),
+ NetworkIntfId: int32(0),
+ Classifier: &openolt.Classifier{
+ EthType: uint32(layers.EthernetTypeIPv4),
+ SrcPort: uint32(68),
+ DstPort: uint32(67),
+ },
+ Action: &openolt.Action{},
+ Priority: int32(100),
+ PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
+ }
+
+ msg := OnuFlowUpdateMessage{
+ PonPortID: 1,
+ OnuID: 1,
+ Flow: &flow,
+ }
+
+ onu.handleFlowUpdate(msg)
+ assert.Equal(t, onu.InternalState.Current(), "dhcp_started")
+ assert.Equal(t, onu.DhcpFlowReceived, true)
+}
+
+func Test_HandleFlowUpdateDhcpNoDhcp(t *testing.T) {
+ onu := createMockOnu(1, 1, 900, 900, false, false)
+
+ onu.InternalState = fsm.NewFSM(
+ "eap_response_success_received",
+ fsm.Events{
+ {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"},
+ },
+ fsm.Callbacks{},
+ )
+
+ flow := openolt.Flow{
+ AccessIntfId: int32(onu.PonPortID),
+ OnuId: int32(onu.ID),
+ UniId: int32(0),
+ FlowId: uint32(onu.ID),
+ FlowType: "downstream",
+ AllocId: int32(0),
+ NetworkIntfId: int32(0),
+ Classifier: &openolt.Classifier{
+ EthType: uint32(layers.EthernetTypeIPv4),
+ SrcPort: uint32(68),
+ DstPort: uint32(67),
+ },
+ Action: &openolt.Action{},
+ Priority: int32(100),
+ PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
+ }
+
+ msg := OnuFlowUpdateMessage{
+ PonPortID: 1,
+ OnuID: 1,
+ Flow: &flow,
+ }
+
+ onu.handleFlowUpdate(msg)
+ assert.Equal(t, onu.InternalState.Current(), "eap_response_success_received")
+ assert.Equal(t, onu.DhcpFlowReceived, true)
+}