blob: 702b31aaabcb700afc68627f3b11dc48594da814 [file] [log] [blame]
Matteo Scandolo378b8c92020-04-16 14:34:22 -07001/*
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
17package devices
18
19import (
Matteo Scandolo4a036262020-08-17 15:56:13 -070020 "github.com/google/gopacket/layers"
Matteo Scandolo378b8c92020-04-16 14:34:22 -070021 "gotest.tools/assert"
Matteo Scandolo4a036262020-08-17 15:56:13 -070022 "net"
Matteo Scandolo378b8c92020-04-16 14:34:22 -070023 "testing"
24)
25
26func Test_Onu_CreateOnu(t *testing.T) {
27
28 olt := OltDevice{
29 ID: 0,
30 }
31 pon := PonPort{
32 ID: 1,
33 Olt: &olt,
34 }
35
Matteo Scandolo4a036262020-08-17 15:56:13 -070036 onu := CreateONU(&olt, &pon, 1, 0, false)
Matteo Scandolo378b8c92020-04-16 14:34:22 -070037
38 assert.Equal(t, onu.Sn(), "BBSM00000101")
Matteo Scandolo5ff80082019-12-20 13:20:57 -080039}
40
Matteo Scandolo4a036262020-08-17 15:56:13 -070041func Test_AddGemPortToService_eapol(t *testing.T) {
Matteo Scandolo5ff80082019-12-20 13:20:57 -080042
Matteo Scandolo4a036262020-08-17 15:56:13 -070043 hsia := Service{Name: "hsia", NeedsEapol: true, CTag: 900}
44 voip := Service{Name: "voip", NeedsEapol: false, CTag: 55}
Matteo Scandolo5ff80082019-12-20 13:20:57 -080045
46 onu := createTestOnu()
47
Matteo Scandolo4a036262020-08-17 15:56:13 -070048 onu.Services = []ServiceIf{&hsia, &voip}
Matteo Scandolo5ff80082019-12-20 13:20:57 -080049
Matteo Scandolo4a036262020-08-17 15:56:13 -070050 onu.addGemPortToService(1024, uint32(layers.EthernetTypeEAPOL), 0, 0)
Matteo Scandolo5ff80082019-12-20 13:20:57 -080051
Matteo Scandolo4a036262020-08-17 15:56:13 -070052 assert.Equal(t, hsia.GemPort, uint32(1024))
53 assert.Equal(t, voip.GemPort, uint32(0))
54}
Matteo Scandolo5ff80082019-12-20 13:20:57 -080055
Matteo Scandolo4a036262020-08-17 15:56:13 -070056func Test_AddGemPortToService_dhcp(t *testing.T) {
Matteo Scandolo5ff80082019-12-20 13:20:57 -080057
Matteo Scandolo4a036262020-08-17 15:56:13 -070058 hsia := Service{Name: "hsia", NeedsEapol: true}
59 voip := Service{Name: "voip", NeedsDhcp: true, CTag: 900}
60 mc := Service{Name: "mc", CTag: 900}
Matteo Scandolo5ff80082019-12-20 13:20:57 -080061
Matteo Scandolo4a036262020-08-17 15:56:13 -070062 onu := createTestOnu()
Matteo Scandolo5ff80082019-12-20 13:20:57 -080063
Matteo Scandolo4a036262020-08-17 15:56:13 -070064 onu.Services = []ServiceIf{&hsia, &voip, &mc}
65
66 onu.addGemPortToService(1025, uint32(layers.EthernetTypeIPv4), 900, 0)
67
68 assert.Equal(t, hsia.GemPort, uint32(0))
69 assert.Equal(t, voip.GemPort, uint32(1025))
70 assert.Equal(t, mc.GemPort, uint32(0))
71}
72
73func Test_AddGemPortToService_dataplane(t *testing.T) {
74
75 hsia := Service{Name: "hsia", NeedsEapol: true, CTag: 900, STag: 500}
76 voip := Service{Name: "voip", NeedsDhcp: true, CTag: 900}
77
78 onu := createTestOnu()
79
80 onu.Services = []ServiceIf{&hsia, &voip}
81
82 onu.addGemPortToService(1024, uint32(layers.EthernetTypeLLC), 500, 900)
83
84 assert.Equal(t, hsia.GemPort, uint32(1024))
85 assert.Equal(t, voip.GemPort, uint32(0))
86}
87
88func Test_FindServiceByMacAddress(t *testing.T) {
89
90 mac := net.HardwareAddr{0x2e, 0x60, byte(1), byte(1), byte(1), byte(2)}
91
92 hsia := Service{Name: "hsia", HwAddress: net.HardwareAddr{0x2e, 0x60, byte(1), byte(1), byte(1), byte(1)}}
93 voip := Service{Name: "voip", HwAddress: mac}
94 vod := Service{Name: "vod", HwAddress: net.HardwareAddr{0x2e, 0x60, byte(1), byte(1), byte(1), byte(3)}}
95
96 onu := createTestOnu()
97
98 onu.Services = []ServiceIf{&hsia, &voip, &vod}
99
100 service, err := onu.findServiceByMacAddress(mac)
101 assert.NilError(t, err)
102 assert.Equal(t, service.HwAddress.String(), mac.String())
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800103}