blob: 74f8e0024a713ebe509e0d544f59fa87730b01c3 [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/hex"
21 "fmt"
22
23 "github.com/google/gopacket"
24)
25
26// GenerateGetPonMode generates "Device/PON Mode" message
27func GenerateGetPonMode() gopacket.SerializableLayer {
28 tibitData := &TOAMGetRequest{
29 // IEEE 1904.2
30 Opcode: 0x03,
31 // OMI Protocol
32 Flags: 0x0050,
33 OAMPDUCode: 0xfe,
34 OUId: []byte{0x2a, 0xea, 0x15},
35 // TiBiT OLT Management Interface
36 TOMIOpcode: 0x01,
37 // Correlation Tag
38 CTBranch: 0x0c,
39 CTType: 0x0c7a,
40 CTLength: 4,
41 CTInstance: getOltInstance(),
42 // Object Context
43 OCBranch: 0x0c,
44 OCType: 0x0dce,
45 OCLength: 4,
46 OCInstance: 0x00000000,
47 // Vd
48 VdBranch: 0xde,
49 VdLeaf: 0x0002,
50 // End
51 EndBranch: 0,
52 }
53 return tibitData
54}
55
56// GetPonMode is a structure for toam message
57type GetPonMode struct {
58 ComResp TOAMGetResponse
59 EcLength uint8
60 EcValue []byte
61 EndBranch uint8
62}
63
64// String returns the string expression of GetPonMode
65func (d *GetPonMode) String() string {
66 message := d.ComResp.String()
67 message = fmt.Sprintf("%s, EcLength:%02x, EcValue:%s EndBranch:%02x", message, d.EcLength, hex.EncodeToString(d.EcValue), d.EndBranch)
68 return message
69}
70
71// Len returns the length of GetPonMode
72func (d *GetPonMode) Len() int {
73 return d.ComResp.Len() + int(d.ComResp.VcLength) + 1
74}
75
76// Decode decodes byte arrays to a data structure
77func (d *GetPonMode) Decode(data []byte) error {
78 d.ComResp.Decode(data)
79 i := d.ComResp.Len()
80 d.EcLength = data[i]
81 i++
82 d.EcValue = data[i : i+int(d.EcLength)]
83 i += int(d.EcLength)
84 d.EndBranch = data[i]
85
86 return nil
87}
88
89// GetPonMode returns a PON mode
90func (d *GetPonMode) GetPonMode() string {
91 return string(d.EcValue)
92}