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 | */ |
Kengof20xx | 05d7402 | 2020-12-21 11:56:38 +0900 | [diff] [blame] | 16 | |
Takahiro Suzuki | d7bf820 | 2020-12-17 20:21:59 +0900 | [diff] [blame] | 17 | package l2oam |
| 18 | |
| 19 | import ( |
| 20 | "encoding/binary" |
| 21 | "encoding/hex" |
| 22 | "fmt" |
| 23 | |
| 24 | "github.com/google/gopacket" |
| 25 | ) |
| 26 | |
| 27 | func GeneratePcscompuTivitcom(oc *TomiObjectContext) 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: 0x81, |
| 37 | // Correlation Tag |
| 38 | CTBranch: 0x0c, |
| 39 | CTType: 0x0c7a, |
| 40 | CTLength: 4, |
| 41 | CTInstance: 0x00000003, |
| 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: 0, |
| 52 | } |
| 53 | |
| 54 | return tibitData |
| 55 | } |
| 56 | |
| 57 | type GetTrafficControlRefTableRes struct { |
| 58 | ComResp TOAMGetResponse |
| 59 | |
| 60 | ECOC []EcOcPONLinkTrafficControlReferenceTable |
| 61 | EndBranch uint8 |
| 62 | } |
| 63 | |
| 64 | type EcOcPONLinkTrafficControlReferenceTable struct { |
| 65 | EcOcLength uint8 |
| 66 | EcOcBranch uint8 |
| 67 | EcOcType uint16 |
| 68 | EcOcLength2 uint8 |
| 69 | EcOcInstance []byte |
| 70 | } |
| 71 | |
| 72 | func (d *GetTrafficControlRefTableRes) String() string { |
| 73 | message := d.ComResp.String() |
| 74 | for k, ec := range d.ECOC { |
| 75 | message = message + "EC[" + string(k) + "],EcOcLength:" + string(ec.EcOcLength) + ",EcOcBranch:" + string(ec.EcOcBranch) + ",EcOcType:" + string(ec.EcOcType) + ",EcOcLength2" + string(ec.EcOcLength2) + ",EcOcInstance:" + hex.EncodeToString(ec.EcOcInstance) |
| 76 | } |
| 77 | message = fmt.Sprintf("%s", message) |
| 78 | return message |
| 79 | |
| 80 | } |
| 81 | |
| 82 | func (d *GetTrafficControlRefTableRes) Decode(data []byte) error { |
| 83 | d.ComResp.Decode(data) |
| 84 | i := d.ComResp.Len() |
| 85 | for _, ec := range d.ECOC { |
| 86 | ec.EcOcLength = data[i] |
| 87 | i++ |
| 88 | ec.EcOcBranch = data[i] |
| 89 | i++ |
| 90 | binary.BigEndian.PutUint16(data[i:i+2], ec.EcOcType) |
| 91 | i = i + 2 |
| 92 | ec.EcOcLength2 = data[i] |
| 93 | i++ |
| 94 | copy(data[i:i+int(ec.EcOcLength2)], ec.EcOcInstance) |
| 95 | i = i + int(ec.EcOcLength2) |
| 96 | } |
| 97 | |
| 98 | d.EndBranch = data[i] |
| 99 | i++ |
| 100 | |
| 101 | return nil |
| 102 | |
| 103 | } |