Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package devices |
| 18 | |
| 19 | import ( |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 20 | "testing" |
| 21 | |
| 22 | "github.com/opencord/bbsim/internal/bbsim/responders/eapol" |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 23 | omcilib "github.com/opencord/bbsim/internal/common/omci" |
Andrea Campanella | 10426e2 | 2021-10-15 17:58:04 +0200 | [diff] [blame] | 24 | me "github.com/opencord/omci-lib-go/v2/generated" |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 25 | |
| 26 | "gotest.tools/assert" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | func Test_Onu_StateMachine_enable(t *testing.T) { |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 30 | onu := createTestOnu() |
Matteo Scandolo | 9f4bf4f | 2021-06-22 09:41:02 +0200 | [diff] [blame] | 31 | assert.Equal(t, onu.InternalState.Current(), OnuStateInitialized) |
| 32 | _ = onu.InternalState.Event(OnuTxDiscover) |
| 33 | assert.Equal(t, onu.InternalState.Current(), OnuStateDiscovered) |
| 34 | _ = onu.InternalState.Event(OnuTxEnable) |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 35 | assert.Equal(t, onu.InternalState.Current(), OnuStateEnabled) |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 38 | func Test_Onu_StateMachine_disable(t *testing.T) { |
| 39 | onu := createTestOnu() |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 40 | onu.InternalState.SetState(OnuStateEnabled) |
| 41 | assert.Equal(t, onu.InternalState.Current(), OnuStateEnabled) |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 42 | |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 43 | onu.Flows = []FlowKey{ |
yasin sapli | c07b952 | 2022-01-27 11:23:54 +0000 | [diff] [blame] | 44 | {ID: 1}, |
| 45 | {ID: 2}, |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 46 | } |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 47 | key := omcilib.OnuAlarmInfoMapKey{ |
| 48 | MeInstance: 257, |
| 49 | MeClassID: me.PhysicalPathTerminationPointEthernetUniClassID, |
| 50 | } |
| 51 | onu.onuAlarmsInfo[key] = omcilib.OnuAlarmInfo{SequenceNo: 1, AlarmBitMap: [28]byte{}} |
| 52 | onu.PonPort.storeOnuId(onu.ID, onu.SerialNumber) |
Andrea Campanella | bef00d5 | 2022-02-04 09:47:52 +0100 | [diff] [blame^] | 53 | onu.PonPort.storeAllocId(1, onu.SerialNumber) |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 54 | onu.PonPort.storeGemPort(1, onu.SerialNumber) |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 55 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 56 | _ = onu.InternalState.Event(OnuTxDisable) |
| 57 | assert.Equal(t, onu.InternalState.Current(), OnuStateDisabled) |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 58 | |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 59 | assert.Equal(t, len(onu.onuAlarmsInfo), 0) |
Andrea Campanella | cc9b166 | 2022-01-26 17:47:48 +0100 | [diff] [blame] | 60 | assert.Equal(t, len(onu.Flows), 0) |
Matteo Scandolo | d15c0b4 | 2021-03-22 11:38:13 -0700 | [diff] [blame] | 61 | assert.Equal(t, len(onu.PonPort.AllocatedOnuIds), 0) |
| 62 | assert.Equal(t, len(onu.PonPort.AllocatedAllocIds), 0) |
| 63 | assert.Equal(t, len(onu.PonPort.AllocatedGemPorts), 0) |
Matteo Scandolo | 47ef64b | 2020-04-20 14:16:07 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Matteo Scandolo | 9f4bf4f | 2021-06-22 09:41:02 +0200 | [diff] [blame] | 66 | func Test_Onu_StateMachine_pon_disable(t *testing.T) { |
| 67 | onu := createTestOnu() |
| 68 | var err error |
| 69 | |
| 70 | onu.InternalState.SetState(OnuStateEnabled) |
| 71 | err = onu.InternalState.Event(OnuTxPonDisable) |
| 72 | assert.NilError(t, err) |
| 73 | assert.Equal(t, OnuStatePonDisabled, onu.InternalState.Current()) |
| 74 | |
| 75 | onu.InternalState.SetState(OnuStateImageDownloadComplete) |
| 76 | err = onu.InternalState.Event(OnuTxPonDisable) |
| 77 | assert.NilError(t, err) |
| 78 | assert.Equal(t, OnuStatePonDisabled, onu.InternalState.Current()) |
| 79 | } |
| 80 | |
| 81 | func Test_Onu_StateMachine_software_image(t *testing.T) { |
| 82 | onu := createTestOnu() |
| 83 | var err error |
| 84 | |
| 85 | // happy path |
| 86 | onu.InternalState.SetState(OnuStateEnabled) |
| 87 | err = onu.InternalState.Event(OnuTxStartImageDownload) |
| 88 | assert.NilError(t, err) |
| 89 | assert.Equal(t, OnuStateImageDownloadStarted, onu.InternalState.Current()) |
| 90 | |
| 91 | err = onu.InternalState.Event(OnuTxProgressImageDownload) |
| 92 | assert.NilError(t, err) |
| 93 | assert.Equal(t, OnuStateImageDownloadInProgress, onu.InternalState.Current()) |
| 94 | |
| 95 | err = onu.InternalState.Event(OnuTxCompleteImageDownload) |
| 96 | assert.NilError(t, err) |
| 97 | assert.Equal(t, OnuStateImageDownloadComplete, onu.InternalState.Current()) |
| 98 | |
| 99 | err = onu.InternalState.Event(OnuTxActivateImage) |
| 100 | assert.NilError(t, err) |
| 101 | assert.Equal(t, OnuStateImageActivated, onu.InternalState.Current()) |
| 102 | |
| 103 | // after image activate we get an ONU reboot, thus the state is back to Enabled before committing |
| 104 | onu.InternalState.SetState(OnuStateEnabled) |
| 105 | err = onu.InternalState.Event(OnuTxCommitImage) |
| 106 | assert.NilError(t, err) |
| 107 | assert.Equal(t, OnuStateImageCommitted, onu.InternalState.Current()) |
| 108 | |
| 109 | // but we should be able to start a new download |
| 110 | err = onu.InternalState.Event(OnuTxStartImageDownload) |
| 111 | assert.NilError(t, err) |
| 112 | assert.Equal(t, OnuStateImageDownloadStarted, onu.InternalState.Current()) |
| 113 | } |
| 114 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 115 | // check that I can go to auth_started only if |
| 116 | // - the GemPort is set |
| 117 | // - the eapolFlow is received |
| 118 | func Test_Onu_StateMachine_eapol_no_flow(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 119 | t.Skip("Needs to be moved in the Service struct") |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 120 | onu := createTestOnu() |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 121 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 122 | onu.InternalState.SetState(OnuStateEnabled) |
| 123 | assert.Equal(t, onu.InternalState.Current(), OnuStateEnabled) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 124 | |
| 125 | // fail as no EapolFlow has been received |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 126 | err := onu.InternalState.Event(eapol.EventStartAuth) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 127 | if err == nil { |
| 128 | t.Fatal("can't start EAPOL without EapolFlow") |
| 129 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 130 | assert.Equal(t, onu.InternalState.Current(), OnuStateEnabled) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 131 | assert.Equal(t, err.Error(), "transition canceled with error: cannot-go-to-auth-started-as-eapol-flow-is-missing") |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 134 | func Test_Onu_StateMachine_eapol_no_gem(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 135 | t.Skip("Needs to be moved in the Service struct") |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 136 | onu := createTestOnu() |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 137 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 138 | onu.InternalState.SetState(OnuStateEnabled) |
| 139 | assert.Equal(t, onu.InternalState.Current(), OnuStateEnabled) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 140 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 141 | // fail has no GemPort has been set |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 142 | err := onu.InternalState.Event(eapol.EventStartAuth) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 143 | if err == nil { |
| 144 | t.Fatal("can't start EAPOL without GemPort") |
| 145 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 146 | assert.Equal(t, onu.InternalState.Current(), OnuStateEnabled) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 147 | assert.Equal(t, err.Error(), "transition canceled with error: cannot-go-to-auth-started-as-gemport-is-missing") |
| 148 | |
| 149 | } |
| 150 | |
| 151 | func Test_Onu_StateMachine_eapol_start(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 152 | t.Skip("Needs to be moved in the Service struct") |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 153 | onu := createTestOnu() |
| 154 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 155 | onu.InternalState.SetState(OnuStateEnabled) |
| 156 | assert.Equal(t, onu.InternalState.Current(), OnuStateEnabled) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 157 | |
| 158 | // succeed |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 159 | _ = onu.InternalState.Event(eapol.EventStartAuth) |
| 160 | assert.Equal(t, onu.InternalState.Current(), eapol.StateAuthStarted) |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | func Test_Onu_StateMachine_eapol_states(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 164 | t.Skip("Needs to be moved in the Service struct") |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 165 | onu := createTestOnu() |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 166 | |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 167 | onu.InternalState.SetState(eapol.StateAuthStarted) |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 168 | |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 169 | assert.Equal(t, onu.InternalState.Current(), eapol.StateAuthStarted) |
| 170 | _ = onu.InternalState.Event(eapol.EventStartSent) |
| 171 | assert.Equal(t, onu.InternalState.Current(), eapol.StateStartSent) |
| 172 | _ = onu.InternalState.Event(eapol.EventResponseIdentitySent) |
| 173 | assert.Equal(t, onu.InternalState.Current(), eapol.StateResponseIdentitySent) |
| 174 | _ = onu.InternalState.Event(eapol.EventResponseChallengeSent) |
| 175 | assert.Equal(t, onu.InternalState.Current(), eapol.StateResponseChallengeSent) |
| 176 | _ = onu.InternalState.Event(eapol.EventResponseSuccessReceived) |
| 177 | assert.Equal(t, onu.InternalState.Current(), eapol.StateResponseSuccessReceived) |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 178 | |
| 179 | // test that we can retrigger EAPOL |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 180 | states := []string{eapol.StateStartSent, eapol.StateResponseIdentitySent, eapol.StateResponseChallengeSent, eapol.StateResponseSuccessReceived, eapol.StateAuthFailed, "dhcp_ack_received", "dhcp_failed"} |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 181 | for _, state := range states { |
| 182 | onu.InternalState.SetState(state) |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 183 | err := onu.InternalState.Event(eapol.EventStartAuth) |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 184 | assert.Equal(t, err, nil) |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 185 | assert.Equal(t, onu.InternalState.Current(), eapol.StateAuthStarted) |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 186 | } |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 189 | // if auth is set to true we can't go from enabled to dhcp_started |
| 190 | func Test_Onu_StateMachine_dhcp_no_auth(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 191 | t.Skip("Needs to be moved in the Service struct") |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 192 | onu := createTestOnu() |
| 193 | |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 194 | onu.InternalState.SetState(OnuStateEnabled) |
| 195 | assert.Equal(t, onu.InternalState.Current(), OnuStateEnabled) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 196 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 197 | err := onu.InternalState.Event("start_dhcp") |
| 198 | if err == nil { |
| 199 | t.Fail() |
| 200 | } |
Matteo Scandolo | cedde46 | 2021-03-09 17:37:16 -0800 | [diff] [blame] | 201 | assert.Equal(t, onu.InternalState.Current(), OnuStateEnabled) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 202 | assert.Equal(t, err.Error(), "transition canceled with error: cannot-go-to-dhcp-started-as-authentication-is-required") |
| 203 | } |
| 204 | |
| 205 | // if the DHCP flow has not been received we can't start authentication |
| 206 | func Test_Onu_StateMachine_dhcp_no_flow(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 207 | t.Skip("Needs to be moved in the Service struct") |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 208 | onu := createTestOnu() |
| 209 | |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 210 | onu.InternalState.SetState(eapol.StateResponseSuccessReceived) |
| 211 | assert.Equal(t, onu.InternalState.Current(), eapol.StateResponseSuccessReceived) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 212 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 213 | err := onu.InternalState.Event("start_dhcp") |
| 214 | if err == nil { |
| 215 | t.Fail() |
| 216 | } |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 217 | assert.Equal(t, onu.InternalState.Current(), eapol.StateResponseSuccessReceived) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 218 | assert.Equal(t, err.Error(), "transition canceled with error: cannot-go-to-dhcp-started-as-dhcp-flow-is-missing") |
| 219 | } |
| 220 | |
| 221 | // if the ONU does not have a GemPort we can't start DHCP |
| 222 | func Test_Onu_StateMachine_dhcp_no_gem(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 223 | t.Skip("Needs to be moved in the Service struct") |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 224 | onu := createTestOnu() |
| 225 | |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 226 | onu.InternalState.SetState(eapol.StateResponseSuccessReceived) |
| 227 | assert.Equal(t, onu.InternalState.Current(), eapol.StateResponseSuccessReceived) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 228 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 229 | err := onu.InternalState.Event("start_dhcp") |
| 230 | if err == nil { |
| 231 | t.Fail() |
| 232 | } |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 233 | assert.Equal(t, onu.InternalState.Current(), eapol.StateResponseSuccessReceived) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 234 | assert.Equal(t, err.Error(), "transition canceled with error: cannot-go-to-dhcp-started-as-gemport-is-missing") |
| 235 | } |
| 236 | |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 237 | func Test_Onu_StateMachine_dhcp_start(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 238 | t.Skip("Needs to be moved in the Service struct") |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 239 | onu := createTestOnu() |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 240 | |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 241 | onu.InternalState.SetState(eapol.StateResponseSuccessReceived) |
| 242 | assert.Equal(t, onu.InternalState.Current(), eapol.StateResponseSuccessReceived) |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 243 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 244 | // default transition |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 245 | _ = onu.InternalState.Event("start_dhcp") |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 246 | assert.Equal(t, onu.InternalState.Current(), "dhcp_started") |
| 247 | } |
| 248 | |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 249 | func Test_Onu_StateMachine_dhcp_states(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 250 | t.Skip("Needs to be moved in the Service struct") |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 251 | onu := createTestOnu() |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 252 | |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 253 | onu.InternalState.SetState("dhcp_started") |
| 254 | |
| 255 | assert.Equal(t, onu.InternalState.Current(), "dhcp_started") |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 256 | _ = onu.InternalState.Event("dhcp_discovery_sent") |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 257 | assert.Equal(t, onu.InternalState.Current(), "dhcp_discovery_sent") |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 258 | _ = onu.InternalState.Event("dhcp_request_sent") |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 259 | assert.Equal(t, onu.InternalState.Current(), "dhcp_request_sent") |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 260 | _ = onu.InternalState.Event("dhcp_ack_received") |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 261 | assert.Equal(t, onu.InternalState.Current(), "dhcp_ack_received") |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 262 | |
| 263 | // test that we can retrigger DHCP |
Elia Battiston | 536a22b | 2022-01-10 10:33:15 +0100 | [diff] [blame] | 264 | states := []string{eapol.StateResponseSuccessReceived, "dhcp_discovery_sent", "dhcp_request_sent", "dhcp_ack_received", "dhcp_failed"} |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 265 | for _, state := range states { |
| 266 | onu.InternalState.SetState(state) |
| 267 | err := onu.InternalState.Event("start_dhcp") |
| 268 | assert.Equal(t, err, nil) |
| 269 | assert.Equal(t, onu.InternalState.Current(), "dhcp_started") |
| 270 | } |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 271 | } |