blob: d55efdc89218bdb3df91acf59ccece1a0ac37b70 [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 */
16
17package l2oam
18
19import (
20 "encoding/binary"
21
22 "github.com/google/gopacket"
23 "github.com/google/gopacket/layers"
24)
25
26// GenerateIngressPort generates "Protocol Filter/Ingress Port" message
27func GenerateIngressPort(OCInstance uint32, isponport bool) gopacket.SerializableLayer {
28
29 var ponPort uint16 = 0x0007
30
31 if !isponport {
32 ponPort = 0x0e07
33 }
34
35 return &SetGenerteIngressPortreq{
36 //IEEE 1904.2
37 Opcode: 0x03,
38 Flags: 0x0050,
39 OAMPDUCode: 0xfe,
40 OUId: []byte{0x2a, 0xea, 0x15},
41 //TiBiT OLT Management Interface
42 TOMIOpcode: 0x03,
43 //Correlation Tag
44 CTBranch: 0x0c,
45 CTType: 0x0c7a,
46 CTLength: 4,
47 CTInstance: getOltInstance(),
48 //Object Context
49 OCBranch: 0x0c,
50 OCType: 0x0cff,
51 OCLength: 4,
52 OCInstance: OCInstance,
53 //Vc
54 VcBranch: 0xcf,
55 VcLeaf: 0x0002,
56 VcLength: 9,
57 //EC OC
58 ECOCLength1: 8,
59 ECOCBranch: 0x0c,
60 ECOCType: ponPort,
61 ECOCLength2: 4,
62 ECOCInstance: 0x00000000,
63 //End
64 EndBranch: 0x00,
65 }
66
67}
68
69// SetGenerteIngressPortreq is a structure for a reqest of "Protocol Filter/Ingress Port" message
70type SetGenerteIngressPortreq struct {
71 layers.BaseLayer
72 Opcode uint8
73 Flags uint16
74 OAMPDUCode uint8
75 OUId []byte // Organizationally Unique Identifier: 2a:ea:15 (Tibit Communications)
76 TOMIOpcode uint8
77 CTBranch uint8
78 CTType uint16
79 CTLength uint8
80 CTInstance uint32
81 OCBranch uint8
82 OCType uint16
83 OCLength uint8
84 OCInstance uint32
85 VcBranch uint8
86 VcLeaf uint16
87 VcLength uint8
88 ECOCLength1 uint8
89 ECOCBranch uint8
90 ECOCType uint16
91 ECOCLength2 uint8
92 ECOCInstance uint32
93 EndBranch uint8
94}
95
96// Len returns the length of SetGenerteIngressPortreq
97func (d *SetGenerteIngressPortreq) Len() int {
98 return 21 + int(d.CTLength) + int(d.OCLength) + int(d.VcLength)
99}
100
101// LayerType returns the ethernet type of SetGenerteIngressPortreq
102func (d *SetGenerteIngressPortreq) LayerType() gopacket.LayerType {
103 return layers.LayerTypeEthernet
104}
105
106// SerializeTo serializes a data structure to byte arrays
107func (d *SetGenerteIngressPortreq) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
108 plen := int(d.Len())
109 data, err := b.PrependBytes(plen)
110 if err != nil {
111 return err
112 }
113
114 i := 0
115 data[i] = byte(d.Opcode)
116 i++
117 binary.BigEndian.PutUint16(data[i:i+2], d.Flags)
118 i += 2
119 data[i] = byte(d.OAMPDUCode)
120 i++
121 copy(data[i:i+len(d.OUId)], d.OUId)
122 i += len(d.OUId)
123 data[i] = byte(d.TOMIOpcode)
124 i++
125 data[i] = byte(d.CTBranch)
126 i++
127 binary.BigEndian.PutUint16(data[i:i+2], d.CTType)
128 i += 2
129 data[i] = byte(d.CTLength)
130 i++
131 binary.BigEndian.PutUint32(data[i:i+4], d.CTInstance)
132 i += 4
133 data[i] = byte(d.OCBranch)
134 i++
135 binary.BigEndian.PutUint16(data[i:i+2], d.OCType)
136 i += 2
137 data[i] = byte(d.OCLength)
138 i++
139 binary.BigEndian.PutUint32(data[i:i+4], d.OCInstance)
140 i += 4
141 data[i] = byte(d.VcBranch)
142 i++
143 binary.BigEndian.PutUint16(data[i:i+2], d.VcLeaf)
144 i += 2
145 data[i] = byte(d.VcLength)
146 i++
147 data[i] = byte(d.ECOCLength1)
148 i++
149 data[i] = byte(d.ECOCBranch)
150 i++
151 binary.BigEndian.PutUint16(data[i:i+2], d.ECOCType)
152 i += 2
153 data[i] = byte(d.ECOCLength2)
154 i++
155 binary.BigEndian.PutUint32(data[i:i+4], d.ECOCInstance)
156 i += 4
157 data[i] = byte(d.EndBranch)
158
159 return nil
160
161}
162
163// Decode decodes byte arrays to a data structure
164func (d *SetGenerteIngressPortreq) Decode(data []byte) error {
165 i := 0
166 d.Opcode = data[i]
167 i++
168 d.Flags = binary.BigEndian.Uint16(data[i : i+2])
169 i += 2
170 d.OAMPDUCode = data[i]
171 i++
172 d.OUId = data[i : i+3]
173 i += len(d.OUId)
174 d.TOMIOpcode = data[i]
175 i++
176 d.CTBranch = data[i]
177 i++
178 d.CTType = binary.BigEndian.Uint16(data[i : i+2])
179 i += 2
180 d.CTLength = data[i]
181 i++
182 d.CTInstance = binary.BigEndian.Uint32(data[i : i+4])
183 i += 4
184 d.OCBranch = data[i]
185 i++
186 d.OCType = binary.BigEndian.Uint16(data[i : i+2])
187 i += 2
188 d.OCLength = data[i]
189 i++
190 d.OCInstance = binary.BigEndian.Uint32(data[i : i+4])
191 i += 4
192 d.VcBranch = data[i]
193 i++
194 d.VcLeaf = binary.BigEndian.Uint16(data[i : i+2])
195 i += 2
196 d.VcLength = data[i]
197 i++
198 d.ECOCLength1 = data[i]
199 i++
200 d.ECOCBranch = data[i]
201 i++
202 d.ECOCType = binary.BigEndian.Uint16(data[i : i+2])
203 i += 2
204 d.ECOCLength2 = data[i]
205 i++
206 d.ECOCInstance = binary.BigEndian.Uint32(data[i : i+4])
207 i += 4
208 d.EndBranch = data[i]
209
210 return nil
211}