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