Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 1 | /* |
Joey Armstrong | 2c03936 | 2024-02-04 18:51:52 -0500 | [diff] [blame^] | 2 | * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 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 | 560e955 | 2022-01-31 10:44:15 +0100 | [diff] [blame] | 20 | "testing" |
| 21 | |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 22 | "github.com/google/gopacket/layers" |
| 23 | "github.com/looplab/fsm" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 24 | "github.com/opencord/bbsim/internal/bbsim/types" |
David K. Bainbridge | c415efe | 2021-08-19 13:05:21 +0000 | [diff] [blame] | 25 | "github.com/opencord/voltha-protos/v5/go/openolt" |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 26 | "gotest.tools/assert" |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 29 | // test that BBR correctly sends the EAPOL Flow |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 30 | func Test_Onu_SendEapolFlow(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 31 | onu := createMockOnu(1, 1) |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 32 | |
| 33 | client := &mockClient{ |
| 34 | FlowAddSpy: FlowAddSpy{ |
| 35 | Calls: make(map[int]*openolt.Flow), |
| 36 | }, |
| 37 | fail: false, |
| 38 | } |
| 39 | |
| 40 | onu.sendEapolFlow(client) |
| 41 | assert.Equal(t, client.FlowAddSpy.CallCount, 1) |
| 42 | |
| 43 | assert.Equal(t, client.FlowAddSpy.Calls[1].AccessIntfId, int32(onu.PonPortID)) |
| 44 | assert.Equal(t, client.FlowAddSpy.Calls[1].OnuId, int32(onu.ID)) |
| 45 | assert.Equal(t, client.FlowAddSpy.Calls[1].UniId, int32(0)) |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 46 | assert.Equal(t, client.FlowAddSpy.Calls[1].FlowId, uint64(onu.ID)) |
Elia Battiston | 560e955 | 2022-01-31 10:44:15 +0100 | [diff] [blame] | 47 | assert.Equal(t, client.FlowAddSpy.Calls[1].FlowType, flowTypeDownstream) |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 48 | assert.Equal(t, client.FlowAddSpy.Calls[1].PortNo, onu.ID) |
| 49 | } |
| 50 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 51 | // checks that the FlowId is added to the list |
| 52 | func Test_HandleFlowAddFlowId(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 53 | onu := createMockOnu(1, 1) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 54 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 55 | // add flow on the first UNI |
| 56 | flow1 := openolt.Flow{ |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 57 | FlowId: 64, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 58 | Classifier: &openolt.Classifier{}, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 59 | PortNo: onu.UniPorts[0].(*UniPort).PortNo, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 60 | } |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 61 | msg1 := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 62 | OnuID: onu.ID, |
| 63 | PonPortID: onu.PonPortID, |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 64 | Flow: &flow1, |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 65 | } |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 66 | onu.handleFlowAdd(msg1) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 67 | assert.Equal(t, len(onu.FlowIds), 1) |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 68 | assert.Equal(t, onu.FlowIds[0], uint64(64)) |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 69 | |
| 70 | // add flow on the second UNI |
| 71 | flow2 := openolt.Flow{ |
| 72 | FlowId: 65, |
| 73 | Classifier: &openolt.Classifier{}, |
| 74 | PortNo: onu.UniPorts[1].(*UniPort).PortNo, |
| 75 | } |
| 76 | msg2 := types.OnuFlowUpdateMessage{ |
| 77 | OnuID: onu.ID, |
| 78 | PonPortID: onu.PonPortID, |
| 79 | Flow: &flow2, |
| 80 | } |
| 81 | onu.handleFlowAdd(msg2) |
| 82 | assert.Equal(t, len(onu.FlowIds), 2) |
| 83 | assert.Equal(t, onu.FlowIds[1], uint64(65)) |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 86 | // checks that we only remove the correct flow |
| 87 | func Test_HandleFlowRemoveFlowId(t *testing.T) { |
| 88 | onu := createMockOnu(1, 1) |
| 89 | |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 90 | onu.FlowIds = []uint64{1, 2, 34, 64, 92} |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 91 | |
| 92 | flow := openolt.Flow{ |
| 93 | FlowId: 64, |
| 94 | Classifier: &openolt.Classifier{}, |
| 95 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 96 | msg := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 97 | OnuID: onu.ID, |
| 98 | PonPortID: onu.PonPortID, |
| 99 | Flow: &flow, |
| 100 | } |
| 101 | onu.handleFlowRemove(msg) |
| 102 | assert.Equal(t, len(onu.FlowIds), 4) |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 103 | assert.Equal(t, onu.FlowIds[0], uint64(1)) |
| 104 | assert.Equal(t, onu.FlowIds[1], uint64(2)) |
| 105 | assert.Equal(t, onu.FlowIds[2], uint64(34)) |
| 106 | assert.Equal(t, onu.FlowIds[3], uint64(92)) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | // checks that when the last flow is removed we reset the stored flags in the ONU |
| 110 | func Test_HandleFlowRemoveFlowId_LastFlow(t *testing.T) { |
| 111 | onu := createMockOnu(1, 1) |
| 112 | |
| 113 | onu.InternalState = fsm.NewFSM( |
| 114 | "enabled", |
| 115 | fsm.Events{ |
| 116 | {Name: "disable", Src: []string{"enabled"}, Dst: "disabled"}, |
| 117 | }, |
| 118 | fsm.Callbacks{}, |
| 119 | ) |
| 120 | |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 121 | onu.FlowIds = []uint64{64} |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 122 | |
| 123 | flow := openolt.Flow{ |
| 124 | FlowId: 64, |
| 125 | Classifier: &openolt.Classifier{}, |
| 126 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 127 | msg := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 128 | OnuID: onu.ID, |
| 129 | PonPortID: onu.PonPortID, |
| 130 | Flow: &flow, |
| 131 | } |
| 132 | onu.handleFlowRemove(msg) |
| 133 | assert.Equal(t, len(onu.FlowIds), 0) |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | func TestOnu_HhandleEAPOLStart(t *testing.T) { |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 137 | // FIXME |
| 138 | t.Skip("move in the UNI") |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 139 | onu := createMockOnu(1, 1) |
| 140 | hsia := mockService{Name: "hsia"} |
| 141 | voip := mockService{Name: "voip"} |
| 142 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 143 | //onu.Services = []ServiceIf{&hsia, &voip} |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 144 | |
| 145 | stream := mockStream{ |
| 146 | Calls: make(map[int]*openolt.Indication), |
| 147 | } |
| 148 | |
| 149 | onu.PonPort.Olt.OpenoltStream = &stream |
| 150 | |
| 151 | flow := openolt.Flow{ |
| 152 | AccessIntfId: int32(onu.PonPortID), |
| 153 | OnuId: int32(onu.ID), |
| 154 | UniId: int32(0), |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 155 | FlowId: uint64(onu.ID), |
Elia Battiston | 560e955 | 2022-01-31 10:44:15 +0100 | [diff] [blame] | 156 | FlowType: flowTypeDownstream, |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 157 | AllocId: int32(0), |
| 158 | NetworkIntfId: int32(0), |
| 159 | Classifier: &openolt.Classifier{ |
| 160 | EthType: uint32(layers.EthernetTypeEAPOL), |
| 161 | OVid: 4091, |
| 162 | }, |
| 163 | Action: &openolt.Action{}, |
| 164 | Priority: int32(100), |
| 165 | PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 166 | } |
| 167 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 168 | msg := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 169 | PonPortID: 1, |
| 170 | OnuID: 1, |
| 171 | Flow: &flow, |
| 172 | } |
| 173 | |
| 174 | onu.handleFlowAdd(msg) |
| 175 | |
| 176 | // check that we call HandleAuth on all the services |
| 177 | assert.Equal(t, hsia.HandleAuthCallCount, 1) |
| 178 | assert.Equal(t, voip.HandleAuthCallCount, 1) |
| 179 | } |
| 180 | |
| 181 | // TODO all the following tests needs to be moved in the Service model |
| 182 | |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 183 | // validates that when an ONU receives an EAPOL flow for UNI 0 |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 184 | // and the GemPort has already been configured |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 185 | // it transition to auth_started state |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 186 | func Test_HandleFlowAddEapolWithGem(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 187 | t.Skip("Needs to be moved in the Service struct") |
| 188 | onu := createMockOnu(1, 1) |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 189 | |
| 190 | onu.InternalState = fsm.NewFSM( |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 191 | "enabled", |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 192 | fsm.Events{ |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 193 | {Name: "start_auth", Src: []string{"enabled"}, Dst: "auth_started"}, |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 194 | }, |
| 195 | fsm.Callbacks{}, |
| 196 | ) |
| 197 | |
| 198 | flow := openolt.Flow{ |
| 199 | AccessIntfId: int32(onu.PonPortID), |
| 200 | OnuId: int32(onu.ID), |
| 201 | UniId: int32(0), |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 202 | FlowId: uint64(onu.ID), |
Elia Battiston | 560e955 | 2022-01-31 10:44:15 +0100 | [diff] [blame] | 203 | FlowType: flowTypeDownstream, |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 204 | AllocId: int32(0), |
| 205 | NetworkIntfId: int32(0), |
| 206 | Classifier: &openolt.Classifier{ |
| 207 | EthType: uint32(layers.EthernetTypeEAPOL), |
| 208 | OVid: 4091, |
| 209 | }, |
| 210 | Action: &openolt.Action{}, |
| 211 | Priority: int32(100), |
| 212 | PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 213 | } |
| 214 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 215 | msg := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 216 | PonPortID: 1, |
| 217 | OnuID: 1, |
| 218 | Flow: &flow, |
| 219 | } |
| 220 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 221 | onu.handleFlowAdd(msg) |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 222 | assert.Equal(t, onu.InternalState.Current(), "auth_started") |
| 223 | } |
| 224 | |
| 225 | // validates that when an ONU receives an EAPOL flow for UNI that is not 0 |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 226 | // no action is taken (this is independent of GemPort status |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 227 | func Test_HandleFlowAddEapolWrongUNI(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 228 | t.Skip("Needs to be moved in the Service struct") |
| 229 | onu := createMockOnu(1, 1) |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 230 | |
| 231 | onu.InternalState = fsm.NewFSM( |
| 232 | "enabled", |
| 233 | fsm.Events{ |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 234 | {Name: "start_auth", Src: []string{"enabled"}, Dst: "auth_started"}, |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 235 | }, |
| 236 | fsm.Callbacks{}, |
| 237 | ) |
| 238 | |
| 239 | flow := openolt.Flow{ |
| 240 | AccessIntfId: int32(onu.PonPortID), |
| 241 | OnuId: int32(onu.ID), |
| 242 | UniId: int32(1), |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 243 | FlowId: uint64(onu.ID), |
Elia Battiston | 560e955 | 2022-01-31 10:44:15 +0100 | [diff] [blame] | 244 | FlowType: flowTypeDownstream, |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 245 | AllocId: int32(0), |
| 246 | NetworkIntfId: int32(0), |
| 247 | Classifier: &openolt.Classifier{ |
| 248 | EthType: uint32(layers.EthernetTypeEAPOL), |
| 249 | OVid: 4091, |
| 250 | }, |
| 251 | Action: &openolt.Action{}, |
| 252 | Priority: int32(100), |
| 253 | PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 254 | } |
| 255 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 256 | msg := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 257 | PonPortID: 1, |
| 258 | OnuID: 1, |
| 259 | Flow: &flow, |
| 260 | } |
| 261 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 262 | onu.handleFlowAdd(msg) |
Matteo Scandolo | 813402b | 2019-10-23 19:24:52 -0700 | [diff] [blame] | 263 | assert.Equal(t, onu.InternalState.Current(), "enabled") |
| 264 | } |
| 265 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 266 | // validates that when an ONU receives a DHCP flow for UNI 0 and pbit 0 |
| 267 | // and the GemPort has already been configured |
| 268 | // it transition to dhcp_started state |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 269 | func Test_HandleFlowAddDhcp(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 270 | t.Skip("Needs to be moved in the Service struct") |
| 271 | onu := createMockOnu(1, 1) |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 272 | |
| 273 | onu.InternalState = fsm.NewFSM( |
| 274 | "eap_response_success_received", |
| 275 | fsm.Events{ |
| 276 | {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"}, |
| 277 | }, |
| 278 | fsm.Callbacks{}, |
| 279 | ) |
| 280 | |
| 281 | flow := openolt.Flow{ |
| 282 | AccessIntfId: int32(onu.PonPortID), |
| 283 | OnuId: int32(onu.ID), |
| 284 | UniId: int32(0), |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 285 | FlowId: uint64(onu.ID), |
Elia Battiston | 560e955 | 2022-01-31 10:44:15 +0100 | [diff] [blame] | 286 | FlowType: flowTypeDownstream, |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 287 | AllocId: int32(0), |
| 288 | NetworkIntfId: int32(0), |
| 289 | Classifier: &openolt.Classifier{ |
| 290 | EthType: uint32(layers.EthernetTypeIPv4), |
| 291 | SrcPort: uint32(68), |
| 292 | DstPort: uint32(67), |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 293 | OPbits: 0, |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 294 | }, |
| 295 | Action: &openolt.Action{}, |
| 296 | Priority: int32(100), |
| 297 | PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 298 | } |
| 299 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 300 | msg := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 301 | PonPortID: 1, |
| 302 | OnuID: 1, |
| 303 | Flow: &flow, |
| 304 | } |
| 305 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 306 | onu.handleFlowAdd(msg) |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 307 | assert.Equal(t, onu.InternalState.Current(), "dhcp_started") |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 310 | // validates that when an ONU receives a DHCP flow for UNI 0 and pbit 255 |
| 311 | // and the GemPort has already been configured |
| 312 | // it transition to dhcp_started state |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 313 | func Test_HandleFlowAddDhcpPBit255(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 314 | t.Skip("Needs to be moved in the Service struct") |
| 315 | onu := createMockOnu(1, 1) |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 316 | |
| 317 | onu.InternalState = fsm.NewFSM( |
| 318 | "eap_response_success_received", |
| 319 | fsm.Events{ |
| 320 | {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"}, |
| 321 | }, |
| 322 | fsm.Callbacks{}, |
| 323 | ) |
| 324 | |
| 325 | flow := openolt.Flow{ |
| 326 | AccessIntfId: int32(onu.PonPortID), |
| 327 | OnuId: int32(onu.ID), |
| 328 | UniId: int32(0), |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 329 | FlowId: uint64(onu.ID), |
Elia Battiston | 560e955 | 2022-01-31 10:44:15 +0100 | [diff] [blame] | 330 | FlowType: flowTypeDownstream, |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 331 | AllocId: int32(0), |
| 332 | NetworkIntfId: int32(0), |
| 333 | Classifier: &openolt.Classifier{ |
| 334 | EthType: uint32(layers.EthernetTypeIPv4), |
| 335 | SrcPort: uint32(68), |
| 336 | DstPort: uint32(67), |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 337 | OPbits: 255, |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 338 | }, |
| 339 | Action: &openolt.Action{}, |
| 340 | Priority: int32(100), |
| 341 | PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 342 | } |
| 343 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 344 | msg := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 345 | PonPortID: 1, |
| 346 | OnuID: 1, |
| 347 | Flow: &flow, |
| 348 | } |
| 349 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 350 | onu.handleFlowAdd(msg) |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 351 | assert.Equal(t, onu.InternalState.Current(), "dhcp_started") |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 354 | // validates that when an ONU receives a DHCP flow for UNI 0 and pbit not 0 or 255 |
| 355 | // and the GemPort has already been configured |
| 356 | // it ignores the message |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 357 | func Test_HandleFlowAddDhcpIgnoreByPbit(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 358 | t.Skip("Needs to be moved in the Service struct") |
| 359 | onu := createMockOnu(1, 1) |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 360 | |
| 361 | onu.InternalState = fsm.NewFSM( |
| 362 | "eap_response_success_received", |
| 363 | fsm.Events{ |
| 364 | {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"}, |
| 365 | }, |
| 366 | fsm.Callbacks{}, |
| 367 | ) |
| 368 | |
| 369 | flow := openolt.Flow{ |
| 370 | AccessIntfId: int32(onu.PonPortID), |
| 371 | OnuId: int32(onu.ID), |
| 372 | UniId: int32(0), |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 373 | FlowId: uint64(onu.ID), |
Elia Battiston | 560e955 | 2022-01-31 10:44:15 +0100 | [diff] [blame] | 374 | FlowType: flowTypeDownstream, |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 375 | AllocId: int32(0), |
| 376 | NetworkIntfId: int32(0), |
| 377 | Classifier: &openolt.Classifier{ |
| 378 | EthType: uint32(layers.EthernetTypeIPv4), |
| 379 | SrcPort: uint32(68), |
| 380 | DstPort: uint32(67), |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 381 | OPbits: 1, |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 382 | }, |
| 383 | Action: &openolt.Action{}, |
| 384 | Priority: int32(100), |
| 385 | PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 386 | } |
| 387 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 388 | msg := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 389 | PonPortID: 1, |
| 390 | OnuID: 1, |
| 391 | Flow: &flow, |
| 392 | } |
| 393 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 394 | onu.handleFlowAdd(msg) |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 395 | assert.Equal(t, onu.InternalState.Current(), "eap_response_success_received") |
Matteo Scandolo | d74abba | 2020-04-16 16:36:44 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 398 | // validates that when an ONU receives a DHCP flow for UNI 0 |
| 399 | // but the noDchp bit is set no action is taken |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 400 | func Test_HandleFlowAddDhcpNoDhcp(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 401 | t.Skip("Needs to be moved in the Service struct") |
| 402 | onu := createMockOnu(1, 1) |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 403 | |
| 404 | onu.InternalState = fsm.NewFSM( |
| 405 | "eap_response_success_received", |
| 406 | fsm.Events{ |
| 407 | {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"}, |
| 408 | }, |
| 409 | fsm.Callbacks{}, |
| 410 | ) |
| 411 | |
| 412 | flow := openolt.Flow{ |
| 413 | AccessIntfId: int32(onu.PonPortID), |
| 414 | OnuId: int32(onu.ID), |
| 415 | UniId: int32(0), |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 416 | FlowId: uint64(onu.ID), |
Elia Battiston | 560e955 | 2022-01-31 10:44:15 +0100 | [diff] [blame] | 417 | FlowType: flowTypeDownstream, |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 418 | AllocId: int32(0), |
| 419 | NetworkIntfId: int32(0), |
| 420 | Classifier: &openolt.Classifier{ |
| 421 | EthType: uint32(layers.EthernetTypeIPv4), |
| 422 | SrcPort: uint32(68), |
| 423 | DstPort: uint32(67), |
| 424 | }, |
| 425 | Action: &openolt.Action{}, |
| 426 | Priority: int32(100), |
| 427 | PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 428 | } |
| 429 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 430 | msg := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 431 | PonPortID: 1, |
| 432 | OnuID: 1, |
| 433 | Flow: &flow, |
| 434 | } |
| 435 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 436 | onu.handleFlowAdd(msg) |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 437 | assert.Equal(t, onu.InternalState.Current(), "eap_response_success_received") |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 438 | } |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 439 | |
| 440 | // validates that when an ONU receives a DHCP flow for UNI 0 and pbit not 0 or 255 |
| 441 | // and the GemPort has not already been configured |
| 442 | // it transition to dhcp_started state |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 443 | func Test_HandleFlowAddDhcpWithoutGem(t *testing.T) { |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 444 | t.Skip("Needs to be moved in the Service struct") |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 445 | // NOTE that this feature is required as there is no guarantee that the gemport is the same |
| 446 | // one we received with the EAPOL flow |
Matteo Scandolo | 4a03626 | 2020-08-17 15:56:13 -0700 | [diff] [blame] | 447 | onu := createMockOnu(1, 1) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 448 | |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 449 | onu.InternalState = fsm.NewFSM( |
| 450 | "enabled", |
| 451 | fsm.Events{ |
| 452 | {Name: "start_dhcp", Src: []string{"enabled"}, Dst: "dhcp_started"}, |
| 453 | }, |
| 454 | fsm.Callbacks{}, |
| 455 | ) |
| 456 | |
| 457 | flow := openolt.Flow{ |
| 458 | AccessIntfId: int32(onu.PonPortID), |
| 459 | OnuId: int32(onu.ID), |
| 460 | UniId: int32(0), |
Matteo Scandolo | 4f4ac79 | 2020-10-01 16:33:21 -0700 | [diff] [blame] | 461 | FlowId: uint64(onu.ID), |
Elia Battiston | 560e955 | 2022-01-31 10:44:15 +0100 | [diff] [blame] | 462 | FlowType: flowTypeDownstream, |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 463 | AllocId: int32(0), |
| 464 | NetworkIntfId: int32(0), |
| 465 | Classifier: &openolt.Classifier{ |
| 466 | EthType: uint32(layers.EthernetTypeIPv4), |
| 467 | SrcPort: uint32(68), |
| 468 | DstPort: uint32(67), |
| 469 | OPbits: 0, |
| 470 | }, |
| 471 | Action: &openolt.Action{}, |
| 472 | Priority: int32(100), |
| 473 | PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU |
| 474 | } |
| 475 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 476 | msg := types.OnuFlowUpdateMessage{ |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 477 | PonPortID: 1, |
| 478 | OnuID: 1, |
| 479 | Flow: &flow, |
| 480 | } |
| 481 | |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 482 | onu.handleFlowAdd(msg) |
Hardik Windlass | 7b3405b | 2020-07-08 15:10:05 +0530 | [diff] [blame] | 483 | } |