blob: a794903e9e4bca49c91927bb947919d431737a98 [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 "encoding/hex"
22 "fmt"
23
24 "github.com/google/gopacket"
25 "github.com/google/gopacket/layers"
26)
27
28// GenerateSetDefaultOutlet generates "Default Outlet" message
29func GenerateSetDefaultOutlet(oc *TomiObjectContext, onuID *TomiObjectContext) gopacket.SerializableLayer {
30
31 tibitData := &DefaultOutletRequest{
32 // IEEE 1904.2
33 Opcode: 0x03,
34 // OAM Protocol
35 Flags: 0x0050,
36 OAMPDUCode: 0xfe,
37 OUId: []byte{0x2a, 0xea, 0x15},
38 // TiBit OLT Management Interface
39 TOMIOpcode: 0x03,
40 // Correlation Tag
41 CTBranch: 0x0c,
42 CTType: 0x0c7a,
43 CTLength: 4,
44 CTInstance: getOltInstance(),
45 // Object Context
46 OCBranch: oc.Branch,
47 OCType: oc.Type,
48 OCLength: oc.Length,
49 OCInstance: oc.Instance,
50 // Vc
51 VcBranch: 0x5d,
52 VcLeaf: 0x0003,
53 VcLength: 0x09,
54 // Default Outlet
55 DOLength: 8,
56 DOBranch: 0x0c,
57 DOType: 0x0011,
58 DOValLength: 4,
59 DOInstance: onuID.Instance,
60 // End
61 EndBranch: 0x00,
62 }
63
64 return tibitData
65}
66
67// DefaultOutletRequest is a structure for a request of "Default Outlet" message
68type DefaultOutletRequest struct {
69 layers.BaseLayer
70 Opcode uint8
71 Flags uint16
72 OAMPDUCode uint8
73 OUId []byte // Organizationally Unique Identifier: 2a:ea:15 (Tibit Communications)
74 TOMIOpcode uint8
75 CTBranch uint8
76 CTType uint16
77 CTLength uint8
78 CTInstance uint32
79 OCBranch uint8
80 OCType uint16
81 OCLength uint8
82 OCInstance uint32
83 VcBranch uint8
84 VcLeaf uint16
85 VcLength uint8
86 DOLength uint8
87 DOBranch uint8
88 DOType uint16
89 DOValLength uint8
90 DOInstance uint32
91 EndBranch uint8
92}
93
94// String returns the string expression of DefaultOutletRequest
95func (d *DefaultOutletRequest) String() string {
96 message := fmt.Sprintf("Opcode:%x, Flags:%x, OAMPDUCode:%x, OUId:%v", d.Opcode, d.Flags, d.OAMPDUCode, hex.EncodeToString(d.OUId))
97 message = fmt.Sprintf("%s, TOMIOpcode:%x", message, d.TOMIOpcode)
98 message = fmt.Sprintf("%s, CTBranch:%x, CTType:%x, CTLength:%x, CTInstance:%x", message, d.CTBranch, d.CTType, d.CTLength, d.CTInstance)
99 message = fmt.Sprintf("%s, OCBranch:%x, OCType:%x, OCLength:%x, OCInstance:%x", message, d.OCBranch, d.OCType, d.OCLength, d.OCInstance)
100 message = fmt.Sprintf("%s, VcBranch:%x, VcLeaf:%x, VcLength:%x", message, d.VcBranch, d.VcLeaf, d.VcLength)
101 message = fmt.Sprintf("%s, DOLength:%x, DOBranch:%x, DOType:%x, DOValLength:%x, DOInstance:%x", message, d.DOLength, d.DOBranch, d.DOType, d.DOValLength, d.DOInstance)
102
103 return message
104}
105
106// Len returns the length of DefaultOutletRequest
107func (d *DefaultOutletRequest) Len() int {
108 return 38
109}
110
111// LayerType returns the ethernet type of DefaultOutletRequest
112func (d *DefaultOutletRequest) LayerType() gopacket.LayerType { return layers.LayerTypeEthernet }
113
114// SerializeTo serializes a data structure to byte arrays
115func (d *DefaultOutletRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
116 plen := int(d.Len())
117 data, err := b.PrependBytes(plen)
118 if err != nil {
119 return err
120 }
121
122 i := 0
123 data[i] = byte(d.Opcode)
124 i++
125 binary.BigEndian.PutUint16(data[i:i+2], d.Flags)
126 i += 2
127 data[i] = byte(d.OAMPDUCode)
128 i++
129 copy(data[i:i+len(d.OUId)], d.OUId)
130 i += len(d.OUId)
131 data[i] = byte(d.TOMIOpcode)
132 i++
133 data[i] = byte(d.CTBranch)
134 i++
135 binary.BigEndian.PutUint16(data[i:i+2], d.CTType)
136 i += 2
137 data[i] = byte(d.CTLength)
138 i++
139 binary.BigEndian.PutUint32(data[i:i+4], d.CTInstance)
140 i += 4
141 data[i] = byte(d.OCBranch)
142 i++
143 binary.BigEndian.PutUint16(data[i:i+2], d.OCType)
144 i += 2
145 data[i] = byte(d.OCLength)
146 i++
147 binary.BigEndian.PutUint32(data[i:i+4], d.OCInstance)
148 i += 4
149 data[i] = byte(d.VcBranch)
150 i++
151 binary.BigEndian.PutUint16(data[i:i+2], d.VcLeaf)
152 i += 2
153 data[i] = byte(d.VcLength)
154 i++
155 data[i] = byte(d.DOLength)
156 i++
157 data[i] = byte(d.DOBranch)
158 i++
159 binary.BigEndian.PutUint16(data[i:i+2], d.DOType)
160 i += 2
161 data[i] = byte(d.DOValLength)
162 i++
163 binary.BigEndian.PutUint32(data[i:i+4], d.DOInstance)
164 i += 4
165 data[i] = byte(d.EndBranch)
166
167 return nil
168}