-
Notifications
You must be signed in to change notification settings - Fork 15
/
E2SM-MHO-ControlHeader.go
49 lines (37 loc) · 1.52 KB
/
E2SM-MHO-ControlHeader.go
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
// SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
//
// SPDX-License-Identifier: Apache-2.0
package encoder
import (
"encoding/hex"
e2smmhov2 "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_mho_go/v2/e2sm-mho-go"
"github.com/onosproject/onos-lib-go/pkg/asn1/aper"
"github.com/onosproject/onos-lib-go/pkg/errors"
"github.com/onosproject/onos-lib-go/pkg/logging"
)
var log = logging.GetLogger()
func PerEncodeE2SmMhoControlHeader(ch *e2smmhov2.E2SmMhoControlHeader) ([]byte, error) {
log.Debugf("Obtained E2SM-RC-PRE-ControlHeader message is\n%v", ch)
if err := ch.Validate(); err != nil {
return nil, errors.NewInvalid("error validating E2SM-MHO-ControlHeader PDU %s", err.Error())
}
per, err := aper.MarshalWithParams(ch, "choiceExt", e2smmhov2.MhoChoicemap, nil)
if err != nil {
return nil, err
}
log.Debugf("Encoded E2SM-RC-PRE-ControlHeader PER bytes are\n%v", hex.Dump(per))
return per, nil
}
func PerDecodeE2SmMhoControlHeader(per []byte) (*e2smmhov2.E2SmMhoControlHeader, error) {
log.Debugf("Obtained E2SM-RC-PRE-ControlHeader PER bytes are\n%v", hex.Dump(per))
result := e2smmhov2.E2SmMhoControlHeader{}
err := aper.UnmarshalWithParams(per, &result, "choiceExt", e2smmhov2.MhoChoicemap, nil)
if err != nil {
return nil, err
}
log.Debugf("Decoded E2SM-RC-PRE-ControlHeader from PER is\n%v", &result)
if err = result.Validate(); err != nil {
return nil, errors.NewInvalid("error validating E2SM-MHO-ControlHeader PDU %s", err.Error())
}
return &result, nil
}