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