-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlayer_ethernet_test.go
155 lines (146 loc) · 20.2 KB
/
layer_ethernet_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package packet
import (
"syscall"
"testing"
)
func DONTestPadding(t *testing.T) {
buf := make([]byte, EthMaxSize) // allocate in the stack
ether := EncodeEther(buf, syscall.ETH_P_IP, routerMAC, mac2)
payload := []byte{0x04, 0x55, 0x33}
var err error
if ether, err = ether.AppendPayload(payload); err != nil {
t.Fatal("error in append ", err)
}
if len(ether) != 60 {
t.Errorf("invalid append payload len= %v", len(ether))
}
ether = EncodeEther(buf, syscall.ETH_P_IPV6, routerMAC, mac2)
if ether, err = ether.SetPayload(payload); err != nil {
t.Fatal("error in append ", err)
}
if len(ether) != 60 {
t.Errorf("invalid payload len= %v", len(ether))
}
}
func TestIEEE1905_IsValid(t *testing.T) {
tests := []struct {
name string
payload []byte
wantErr bool
}{
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x55, 0x2d, 0xe9, 0xb2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x16, 0xc5, 0x4b, 0xfe, 0xca, 0x82, 0x19, 0x7e, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0xfe, 0x1b, 0xc0, 0x05, 0xad, 0xc7, 0x96, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x0d, 0x58, 0x00, 0xcd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x66, 0x8f, 0x9e, 0xe9, 0xec, 0x8c, 0x77, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x52, 0x2d, 0x55, 0x2d, 0x54, 0x48, 0x45, 0x52, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x52, 0x2d, 0x55, 0x2d, 0x54, 0x48, 0x45, 0x52, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x07, 0x64, 0x72, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0xec, 0x70, 0x05, 0x8a, 0x2a, 0x99, 0x90, 0xf6, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x04, 0x04, 0xfc, 0x1a, 0x00, 0x00, 0x22, 0x22, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xee, 0x64, 0xf8, 0x1e, 0xce, 0xcb, 0x12, 0x77, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x72, 0xa5, 0x69, 0x0a, 0x78, 0x51, 0x1c, 0xb7, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x74, 0x72, 0x31, 0x06, 0x64, 0x6e, 0x73, 0x70, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35, 0x96, 0x58, 0x00, 0x7b, 0x17, 0xd8, 0x21, 0xdd, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0xc8, 0x66, 0x7e, 0xb9, 0x0b, 0x33, 0xdf, 0x80, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcf, 0x0a, 0x00, 0x04, 0x00, 0x00, 0x1d, 0x0f, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61, 0x63}},
{wantErr: true, payload: []byte{0x0a, 0x6c, 0x6f, 0x6f, 0x70, 0x62, 0x61}}, // invalid packet
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := IEEE1905(tt.payload)
if err := p.IsValid(); (err != nil) != tt.wantErr {
t.Errorf("IEEE1905.IsValid() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.wantErr == true {
return
}
Logger.Msg("test" + "ieee test packet").Struct(p).Write()
})
}
}
func TestEthernetPauseFrame_IsValid(t *testing.T) {
tests := []struct {
name string
payload []byte
wantErr bool
}{
{wantErr: false, payload: []byte{0x00, 0x01, 0xff, 0xff, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0x00, 0x00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0xff, 0xff, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0x00, 0x00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0xff, 0xff, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0x00, 0x00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0xff, 0xff, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0x00, 0x00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0xff, 0xff, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0x00, 0x00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0xff, 0xff, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0x00, 0x00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0xff, 0xff, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0x00, 0x00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0xff, 0xff, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: false, payload: []byte{0x00, 0x01, 0x00, 0x00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: true, payload: []byte{0x00, 0x02, 0x00, 0x00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}},
{wantErr: true, payload: []byte{0x00, 0x02, 0x00, 0x00, 00, 00, 00}}, // invalid
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := EthernetPause(tt.payload)
if err := p.IsValid(); (err != nil) != tt.wantErr {
t.Errorf("EthernetPauseframe.IsValid() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.wantErr == true {
return
}
Logger.Msg("test" + "ethernet pause test packet").Struct(p).Write()
})
}
}
func TestLLPDFrame_IsValid(t *testing.T) {
tests := []struct {
name string
payload []byte
wantErr bool
}{
{wantErr: false, payload: []byte{0x02, 0x07, 0x04, 0xb4, 0xfb, 0xe4, 0x76, 0x2e, 0x0b, 0x04, 0x07, 0x03, 0xb4, 0xfb, 0xe4, 0x76, 0x2e, 0x0b, 0x06, 0x02, 0x00, 0x78, 0x0a, 0x0f, 0x55, 0x6e, 0x69, 0x66, 0x69, 0x45, 0x73, 0x63, 0x72, 0x69, 0x74, 0x6f, 0x72, 0x69, 0x6f, 0x0c, 0x19, 0x55, 0x41, 0x50, 0x2d, 0x41, 0x43, 0x2d, 0x4c, 0x69, 0x74, 0x65, 0x2c, 0x20, 0x34, 0x2e, 0x33, 0x2e, 0x32, 0x38, 0x2e, 0x31, 0x31, 0x33, 0x36, 0x31, 0x0e, 0x04, 0x00, 0x9c, 0x00, 0x0c, 0x10, 0x0c, 0x05, 0x01, 0xc0, 0xa8, 0x01, 0x86, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x18, 0x11, 0x02, 0x28, 0x04, 0x01, 0x90, 0x02, 0x0d, 0x8e, 0x00, 0xb6, 0xfb, 0xe4, 0xff, 0xfe, 0x76, 0x2e, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x03, 0x62, 0x72, 0x30, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x12, 0xbb, 0x01, 0x00, 0x3f, 0x04, 0xfe, 0x0b, 0x00, 0x12, 0xbb, 0x07, 0x34, 0x2e, 0x34, 0x2e, 0x31, 0x35, 0x33, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x02, 0x07, 0x04, 0xb4, 0xfb, 0xe4, 0x76, 0x18, 0xcf, 0x04, 0x07, 0x03, 0xb4, 0xfb, 0xe4, 0x76, 0x18, 0xcf, 0x06, 0x02, 0x00, 0x78, 0x0a, 0x09, 0x55, 0x6e, 0x69, 0x66, 0x69, 0x53, 0x61, 0x6c, 0x61, 0x0c, 0x19, 0x55, 0x41, 0x50, 0x2d, 0x41, 0x43, 0x2d, 0x4c, 0x69, 0x74, 0x65, 0x2c, 0x20, 0x34, 0x2e, 0x33, 0x2e, 0x32, 0x38, 0x2e, 0x31, 0x31, 0x33, 0x36, 0x31, 0x0e, 0x04, 0x00, 0x9c, 0x00, 0x0c, 0x10, 0x0c, 0x05, 0x01, 0xc0, 0xa8, 0x01, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x18, 0x11, 0x02, 0x28, 0x04, 0x01, 0x90, 0x02, 0x0d, 0x8e, 0x00, 0xb6, 0xfb, 0xe4, 0xff, 0xfe, 0x76, 0x18, 0xcf, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x03, 0x62, 0x72, 0x30, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x12, 0xbb, 0x01, 0x00, 0x3f, 0x04, 0xfe, 0x0b, 0x00, 0x12, 0xbb, 0x07, 0x34, 0x2e, 0x34, 0x2e, 0x31, 0x35, 0x33, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x02, 0x07, 0x04, 0xb4, 0xfb, 0xe4, 0x76, 0x2e, 0x0b, 0x04, 0x07, 0x03, 0xb4, 0xfb, 0xe4, 0x76, 0x2e, 0x0b, 0x06, 0x02, 0x00, 0x78, 0x0a, 0x0f, 0x55, 0x6e, 0x69, 0x66, 0x69, 0x45, 0x73, 0x63, 0x72, 0x69, 0x74, 0x6f, 0x72, 0x69, 0x6f, 0x0c, 0x19, 0x55, 0x41, 0x50, 0x2d, 0x41, 0x43, 0x2d, 0x4c, 0x69, 0x74, 0x65, 0x2c, 0x20, 0x34, 0x2e, 0x33, 0x2e, 0x32, 0x38, 0x2e, 0x31, 0x31, 0x33, 0x36, 0x31, 0x0e, 0x04, 0x00, 0x9c, 0x00, 0x0c, 0x10, 0x0c, 0x05, 0x01, 0xc0, 0xa8, 0x01, 0x86, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x18, 0x11, 0x02, 0x28, 0x04, 0x01, 0x90, 0x02, 0x0d, 0x8e, 0x00, 0xb6, 0xfb, 0xe4, 0xff, 0xfe, 0x76, 0x2e, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x03, 0x62, 0x72, 0x30, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x12, 0xbb, 0x01, 0x00, 0x3f, 0x04, 0xfe, 0x0b, 0x00, 0x12, 0xbb, 0x07, 0x34, 0x2e, 0x34, 0x2e, 0x31, 0x35, 0x33, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x02, 0x07, 0x04, 0xb4, 0xfb, 0xe4, 0x76, 0x18, 0xcf, 0x04, 0x07, 0x03, 0xb4, 0xfb, 0xe4, 0x76, 0x18, 0xcf, 0x06, 0x02, 0x00, 0x78, 0x0a, 0x09, 0x55, 0x6e, 0x69, 0x66, 0x69, 0x53, 0x61, 0x6c, 0x61, 0x0c, 0x19, 0x55, 0x41, 0x50, 0x2d, 0x41, 0x43, 0x2d, 0x4c, 0x69, 0x74, 0x65, 0x2c, 0x20, 0x34, 0x2e, 0x33, 0x2e, 0x32, 0x38, 0x2e, 0x31, 0x31, 0x33, 0x36, 0x31, 0x0e, 0x04, 0x00, 0x9c, 0x00, 0x0c, 0x10, 0x0c, 0x05, 0x01, 0xc0, 0xa8, 0x01, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x18, 0x11, 0x02, 0x28, 0x04, 0x01, 0x90, 0x02, 0x0d, 0x8e, 0x00, 0xb6, 0xfb, 0xe4, 0xff, 0xfe, 0x76, 0x18, 0xcf, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x03, 0x62, 0x72, 0x30, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x12, 0xbb, 0x01, 0x00, 0x3f, 0x04, 0xfe, 0x0b, 0x00, 0x12, 0xbb, 0x07, 0x34, 0x2e, 0x34, 0x2e, 0x31, 0x35, 0x33, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x02, 0x07, 0x04, 0xb4, 0xfb, 0xe4, 0x76, 0x18, 0xcf, 0x04, 0x07, 0x03, 0xb4, 0xfb, 0xe4, 0x76, 0x18, 0xcf, 0x06, 0x02, 0x00, 0x78, 0x0a, 0x09, 0x55, 0x6e, 0x69, 0x66, 0x69, 0x53, 0x61, 0x6c, 0x61, 0x0c, 0x19, 0x55, 0x41, 0x50, 0x2d, 0x41, 0x43, 0x2d, 0x4c, 0x69, 0x74, 0x65, 0x2c, 0x20, 0x34, 0x2e, 0x33, 0x2e, 0x32, 0x38, 0x2e, 0x31, 0x31, 0x33, 0x36, 0x31, 0x0e, 0x04, 0x00, 0x9c, 0x00, 0x0c, 0x10, 0x0c, 0x05, 0x01, 0xc0, 0xa8, 0x01, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x18, 0x11, 0x02, 0x28, 0x04, 0x01, 0x90, 0x02, 0x0d, 0x8e, 0x00, 0xb6, 0xfb, 0xe4, 0xff, 0xfe, 0x76, 0x18, 0xcf, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x03, 0x62, 0x72, 0x30, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x12, 0xbb, 0x01, 0x00, 0x3f, 0x04, 0xfe, 0x0b, 0x00, 0x12, 0xbb, 0x07, 0x34, 0x2e, 0x34, 0x2e, 0x31, 0x35, 0x33, 0x00, 0x00}},
{wantErr: false, payload: []byte{0x02, 0x07, 0x04, 0xb4, 0xfb, 0xe4, 0x76, 0x2e, 0x0b, 0x04, 0x07, 0x03, 0xb4, 0xfb, 0xe4, 0x76, 0x2e, 0x0b, 0x06, 0x02, 0x00, 0x78, 0x0a, 0x0f, 0x55, 0x6e, 0x69, 0x66, 0x69, 0x45, 0x73, 0x63, 0x72, 0x69, 0x74, 0x6f, 0x72, 0x69, 0x6f, 0x0c, 0x19, 0x55, 0x41, 0x50, 0x2d, 0x41, 0x43, 0x2d, 0x4c, 0x69, 0x74, 0x65, 0x2c, 0x20, 0x34, 0x2e, 0x33, 0x2e, 0x32, 0x38, 0x2e, 0x31, 0x31, 0x33, 0x36, 0x31, 0x0e, 0x04, 0x00, 0x9c, 0x00, 0x0c, 0x10, 0x0c, 0x05, 0x01, 0xc0, 0xa8, 0x01, 0x86, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x18, 0x11, 0x02, 0x28, 0x04, 0x01, 0x90, 0x02, 0x0d, 0x8e, 0x00, 0xb6, 0xfb, 0xe4, 0xff, 0xfe, 0x76, 0x2e, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x03, 0x62, 0x72, 0x30, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x12, 0xbb, 0x01, 0x00, 0x3f, 0x04, 0xfe, 0x0b, 0x00, 0x12, 0xbb, 0x07, 0x34, 0x2e, 0x34, 0x2e, 0x31, 0x35, 0x33, 0x00, 0x00}},
{wantErr: true, payload: []byte{0x02, 0x07}}, //invalid len
}
// layerTable = append(layerTable, LayerProcessor{EtherType: 0x88cc, Function: ProcessLLDP})
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := LLDP(tt.payload)
if err := p.IsValid(); (err != nil) != tt.wantErr {
t.Errorf("LLDP.IsValid() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.wantErr == true {
return
}
Logger.Msg("test" + "LLDP packet").Struct(p).Write()
})
}
}
/**
TODO: create ethernet 0x880a frame type
examples 0x880a packets
Sep 30 03:09:39 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 22 90 a8 a6 8e 0a 3c fd 0d f5 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
Sep 30 03:09:39 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 52 54 e5 52 60 83 e7 bd 10 ab 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
Sep 30 03:09:39 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 01 4e 6f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
Sep 30 03:09:39 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 22 90 a8 a6 5e f7 cb 6d 1b f1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
Sep 30 03:09:40 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 bb e4 ad 05 3a ef 39 4e a6 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
Sep 30 03:09:41 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 22 90 a8 a6 d5 ec d6 a6 a3 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
Sep 30 03:09:41 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 22 90 a8 a6 e6 03 dd 5e 76 f9 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
Sep 30 03:09:41 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
Sep 30 03:09:41 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 33 69 eb 10 b5 e9 f1 32 fd 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
Sep 30 03:09:42 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 75 78 61 78 2d 32 76 35 65 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
Sep 30 03:09:42 netfilter netfilter[6597]: engine: "unexpected ethernet type" type=0x880a src=e0:19:54:cc:1c:6e dst=ff:ff:ff:ff:ff:ff len=60 payload=[0a 6c 6f 6f 70 62 61 63 6b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 90 a8 a6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]
*/