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