1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2019-2020 UPF-N4 authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
package ie
import (
"encoding/binary"
"io"
)
// NewMBR creates a new MBR IE.
func NewMBR(ul, dl uint32) *IE {
i := New(MBR, make([]byte, 8))
binary.BigEndian.PutUint32(i.Payload[0:4], ul)
binary.BigEndian.PutUint32(i.Payload[4:8], dl)
return i
}
// MBR returns MBR in []byte if the type of IE matches.
func (i *IE) MBR() ([]byte, error) {
if i.Type != MBR {
return nil, &InvalidTypeError{Type: i.Type}
}
return i.Payload, nil
}
// MBRUL returns MBRUL in uint32 if the type of IE matches.
func (i *IE) MBRUL() (uint32, error) {
if i.Type != MBR {
return 0, &InvalidTypeError{Type: i.Type}
}
if len(i.Payload) < 4 {
return 0, io.ErrUnexpectedEOF
}
return binary.BigEndian.Uint32(i.Payload[0:4]), nil
}
// MBRDL returns MBRDL in uint32 if the type of IE matches.
func (i *IE) MBRDL() (uint32, error) {
if i.Type != MBR {
return 0, &InvalidTypeError{Type: i.Type}
}
if len(i.Payload) < 8 {
return 0, io.ErrUnexpectedEOF
}
return binary.BigEndian.Uint32(i.Payload[4:8]), nil
}