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