blob: aa80fcd9221b835b05332590c25e21c189fbce5d [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// GnerateGetVendorName generates "Device/Vendor Name"
27func GnerateGetVendorName() gopacket.SerializableLayer {
28 tibitData := &TOAMGetRequest{
29 // IEEE 1904.2
30 Opcode: 0x03,
31 // OAM 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: 0x0009,
50 // End
51 EndBranch: 0x00,
52 }
53
54 return tibitData
55}
56
57// GetVendorNameRes is a structure for a response of "Device/Vendor Name" message
58type GetVendorNameRes struct {
59 ComResp TOAMGetResponse
60 EcLength uint8
61 EcValue []byte
62 EndBranch uint8
63}
64
65// String returns the string expression of GetVendorNameRes
66func (d *GetVendorNameRes) String() string {
67 message := d.ComResp.String()
68 message = fmt.Sprintf("%s, EcLength:%v, EcValue:%v, EndBranch:%v", message, d.EcLength, hex.EncodeToString(d.EcValue), d.EndBranch)
69 return message
70}
71
72// Len returns the length of GetVendorNameRes
73func (d *GetVendorNameRes) Len() int {
74 return d.ComResp.Len() + int(d.ComResp.VcLength) + 1
75}
76
77// Decode decodes byte arrays to a data structure
78func (d *GetVendorNameRes) Decode(data []byte) error {
79 d.ComResp.Decode(data)
80 i := d.ComResp.Len()
81 d.EcLength = data[i]
82 i++
83 d.EcValue = data[i : i+int(d.EcLength)]
84 i = i + int(d.EcLength)
85 d.EndBranch = data[i]
86
87 return nil
88}
89
90// GetVendorName returns a vendor name
91func (d *GetVendorNameRes) GetVendorName() string {
92 return string(d.EcValue)
93}