blob: 25bfb490c6f8e2c9243fabc0e363eb67848b7d82 [file] [log] [blame]
Takahiro Suzukid7bf8202020-12-17 20:21:59 +09001/*
2 * Copyright 2020-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 */
16package l2oam
17
18import (
19 "encoding/binary"
20 "reflect"
21 "testing"
22
23 "github.com/google/gopacket"
24)
25
26func TestGenerateBestEffortRate(t *testing.T) {
27 type args struct {
28 ecvalue []byte
29 trafficProfile []byte
30 }
31 tests := []struct {
32 name string
33 args args
34 want gopacket.SerializableLayer
35 }{
36 // TODO: Add test cases.
37 {
38 name: "GenerateBestEffortRate-1",
39 args: args{
40 ecvalue: []byte{0x00, 0x4c, 0x4b, 0x40},
41 trafficProfile: []byte{0x00, 0x00, 0x00, 0x01},
42 },
43 want: &TOAMSetRequest{
44 // IEEE 1904.2
45 Opcode: 0x03,
46 // OAM Protocol
47 Flags: 0x0050,
48 OAMPDUCode: 0xfe,
49 OUId: []byte{0x2a, 0xea, 0x15},
50 // TiBit OLT Management Interface
51 TOMIOpcode: 0x03,
52 // Correlation Tag
53 CTBranch: 0x0c,
54 CTType: 0x0c7a,
55 CTLength: 4,
56 CTInstance: getOltInstance() + 1,
57 // Object Context
58 OCBranch: 0x0c,
59 OCType: 0x070f,
60 OCLength: 4,
61 OCInstance: binary.BigEndian.Uint32([]byte{0x00, 0x00, 0x00, 0x01}),
62 // Vc
63 VcBranch: 0x7f,
64 VcLeaf: 0x0008,
65 VcLength: 5, //5
66 // EC
67 ECLength: 4, //4
68 ECValue: []byte{0x00, 0x4c, 0x4b, 0x40}, //[]byte{0x00, 0x4c, 0x4b, 0x40}
69 // End
70 EndBranch: 0x00,
71 },
72 },
73 }
74 for _, tt := range tests {
75 t.Run(tt.name, func(t *testing.T) {
76 if got := GenerateBestEffortRate(tt.args.ecvalue, tt.args.trafficProfile); !reflect.DeepEqual(got, tt.want) {
77 t.Errorf("GenerateBestEffortRate() = %v, want %v", got, tt.want)
78 }
79 })
80 }
81}