Takahiro Suzuki | d7bf820 | 2020-12-17 20:21:59 +0900 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package l2oam |
| 18 | |
| 19 | import ( |
| 20 | "encoding/binary" |
| 21 | |
| 22 | "github.com/google/gopacket" |
| 23 | "github.com/google/gopacket/layers" |
| 24 | ) |
| 25 | |
| 26 | // GenerateGetTrafficControlReferenceTableReq generates "PON Link/Traffic Control Reference Table" message |
| 27 | func GenerateGetTrafficControlReferenceTableReq(oc *TomiObjectContext) gopacket.SerializableLayer { |
| 28 | data := &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: oc.Branch, |
| 44 | OCType: oc.Type, |
| 45 | OCLength: oc.Length, |
| 46 | OCInstance: oc.Instance, |
| 47 | // Vd |
| 48 | VdBranch: 0x01, |
| 49 | VdLeaf: 0x0007, |
| 50 | // End |
| 51 | EndBranch: 0x00, |
| 52 | } |
| 53 | |
| 54 | return data |
| 55 | } |
| 56 | |
| 57 | // GetTrafficControlReferenceTableRes is a structure for a response of "Traffic Control Reference Table" message |
| 58 | type GetTrafficControlReferenceTableRes struct { |
| 59 | layers.BaseLayer |
| 60 | Opcode uint8 |
| 61 | Flags uint16 |
| 62 | OAMPDUCode uint8 |
| 63 | OUId []byte // Organizationally Unique Identifier: 2a:ea:15 (Tibit Communications) |
| 64 | TOMIOpcode uint8 |
| 65 | CTBranch uint8 |
| 66 | CTType uint16 |
| 67 | CTLength uint8 |
| 68 | CTInstance uint32 |
| 69 | OCBranch uint8 |
| 70 | OCType uint16 |
| 71 | OCLength uint8 |
| 72 | OCInstance uint32 |
| 73 | VcBranch uint8 |
| 74 | VcLeaf uint16 |
| 75 | VcLength uint8 |
| 76 | |
| 77 | EcOcLengthDown uint8 |
| 78 | EcOcBranchDown uint8 |
| 79 | EcOcTypeDown uint16 |
| 80 | EcOcLength2Down uint8 |
| 81 | EcOcInstanceDown []byte |
| 82 | |
| 83 | EcOcLengthUp uint8 |
| 84 | EcOcBranchUp uint8 |
| 85 | EcOcTypeUp uint16 |
| 86 | EcOcLength2Up uint8 |
| 87 | EcOcInstanceUp []byte |
| 88 | |
| 89 | EndBranch uint8 |
| 90 | } |
| 91 | |
| 92 | // Decode decodes byte arrays to a data structure |
| 93 | func (d *GetTrafficControlReferenceTableRes) Decode(data []byte) error { |
| 94 | i := 0 |
| 95 | d.Opcode = data[i] |
| 96 | i++ |
| 97 | d.Flags = binary.BigEndian.Uint16(data[i : i+2]) |
| 98 | i += 2 |
| 99 | d.OAMPDUCode = data[i] |
| 100 | i++ |
| 101 | d.OUId = data[i : i+3] |
| 102 | i += len(d.OUId) |
| 103 | d.TOMIOpcode = data[i] |
| 104 | i++ |
| 105 | d.CTBranch = data[i] |
| 106 | i++ |
| 107 | d.CTType = binary.BigEndian.Uint16(data[i : i+2]) |
| 108 | i += 2 |
| 109 | d.CTLength = data[i] |
| 110 | i++ |
| 111 | d.CTInstance = binary.BigEndian.Uint32(data[i : i+4]) |
| 112 | i += 4 |
| 113 | d.OCBranch = data[i] |
| 114 | i++ |
| 115 | d.OCType = binary.BigEndian.Uint16(data[i : i+2]) |
| 116 | i += 2 |
| 117 | d.OCLength = data[i] |
| 118 | i++ |
| 119 | d.OCInstance = binary.BigEndian.Uint32(data[i : i+4]) |
| 120 | i += 4 |
| 121 | d.VcBranch = data[i] |
| 122 | i++ |
| 123 | d.VcLeaf = binary.BigEndian.Uint16(data[i : i+2]) |
| 124 | i += 2 |
| 125 | d.VcLength = data[i] |
| 126 | i++ |
| 127 | |
| 128 | d.EcOcLengthDown = data[i] |
| 129 | i++ |
| 130 | d.EcOcBranchDown = data[i] |
| 131 | i++ |
| 132 | d.EcOcTypeDown = binary.BigEndian.Uint16(data[i : i+2]) |
| 133 | i += 2 |
| 134 | d.EcOcLength2Down = data[i] |
| 135 | i++ |
| 136 | d.EcOcInstanceDown = data[i : i+int(d.EcOcLength2Down)] |
| 137 | i += int(d.EcOcLength2Down) |
| 138 | |
| 139 | d.EcOcLengthUp = data[i] |
| 140 | i++ |
| 141 | d.EcOcBranchUp = data[i] |
| 142 | i++ |
| 143 | d.EcOcTypeUp = binary.BigEndian.Uint16(data[i : i+2]) |
| 144 | i += 2 |
| 145 | d.EcOcLength2Up = data[i] |
| 146 | i++ |
| 147 | d.EcOcInstanceUp = data[i : i+int(d.EcOcLength2Up)] |
| 148 | i += int(d.EcOcLength2Up) |
| 149 | |
| 150 | d.EndBranch = data[i] |
| 151 | |
| 152 | return nil |
| 153 | } |
| 154 | |
| 155 | // GetReferenceControlDown returns a link id for downstream |
| 156 | func (d *GetTrafficControlReferenceTableRes) GetReferenceControlDown() []byte { |
| 157 | return d.EcOcInstanceDown |
| 158 | } |
| 159 | |
| 160 | // GetReferenceControlUp returns a link id for upstream |
| 161 | func (d *GetTrafficControlReferenceTableRes) GetReferenceControlUp() []byte { |
| 162 | return d.EcOcInstanceUp |
| 163 | } |