kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | ================================================================================== |
| 3 | Copyright (c) 2019 AT&T Intellectual Property. |
| 4 | Copyright (c) 2019 Nokia |
| 5 | |
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | you may not use this file except in compliance with the License. |
| 8 | You may obtain a copy of the License at |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 12 | Unless required by applicable law or agreed to in writing, software |
| 13 | distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | See the License for the specific language governing permissions and |
| 16 | limitations under the License. |
| 17 | ================================================================================== |
| 18 | */ |
| 19 | |
| 20 | package control |
| 21 | |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 22 | /* |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 23 | #cgo LDFLAGS: -le2ap_wrapper -le2ap |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 24 | */ |
| 25 | import "C" |
| 26 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 27 | import ( |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 28 | "encoding/hex" |
| 29 | "fmt" |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 30 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" |
| 31 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 32 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 33 | ) |
| 34 | |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 35 | var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer() |
| 36 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 37 | type E2ap struct { |
| 38 | } |
| 39 | |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 40 | //----------------------------------------------------------------------------- |
| 41 | // |
| 42 | //----------------------------------------------------------------------------- |
| 43 | func (c *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) { |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 44 | e2SubReq := packerif.NewPackerSubscriptionRequest() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 45 | err, subReq := e2SubReq.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 46 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 47 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 48 | } |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 49 | return subReq, nil |
| 50 | } |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 51 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 52 | func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 53 | e2SubReq := packerif.NewPackerSubscriptionRequest() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 54 | err, packedData := e2SubReq.Pack(req) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 55 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 56 | return 0, nil, err |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 57 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 58 | return xapp.RIC_SUB_REQ, packedData, nil |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | //----------------------------------------------------------------------------- |
| 62 | // |
| 63 | //----------------------------------------------------------------------------- |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 64 | func (c *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) { |
| 65 | e2SubResp := packerif.NewPackerSubscriptionResponse() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 66 | err, subResp := e2SubResp.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 67 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 68 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 69 | } |
| 70 | return subResp, nil |
| 71 | } |
| 72 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 73 | func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 74 | e2SubResp := packerif.NewPackerSubscriptionResponse() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 75 | err, packedData := e2SubResp.Pack(req) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 76 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 77 | return 0, nil, err |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 78 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 79 | return xapp.RIC_SUB_RESP, packedData, nil |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | //----------------------------------------------------------------------------- |
| 83 | // |
| 84 | //----------------------------------------------------------------------------- |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 85 | func (c *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) { |
| 86 | e2SubFail := packerif.NewPackerSubscriptionFailure() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 87 | err, subFail := e2SubFail.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 88 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 89 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 90 | } |
| 91 | return subFail, nil |
| 92 | } |
| 93 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 94 | func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 95 | e2SubFail := packerif.NewPackerSubscriptionFailure() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 96 | err, packedData := e2SubFail.Pack(req) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 97 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 98 | return 0, nil, err |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 99 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 100 | return xapp.RIC_SUB_FAILURE, packedData, nil |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | //----------------------------------------------------------------------------- |
| 104 | // |
| 105 | //----------------------------------------------------------------------------- |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 106 | func (c *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) { |
| 107 | e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 108 | err, subDelReq := e2SubDelReq.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 109 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 110 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 111 | } |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 112 | return subDelReq, nil |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 113 | } |
| 114 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 115 | func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 116 | e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 117 | err, packedData := e2SubDelReq.Pack(req) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 118 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 119 | return 0, nil, err |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 120 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 121 | return xapp.RIC_SUB_DEL_REQ, packedData, nil |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 122 | } |
| 123 | |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 124 | //----------------------------------------------------------------------------- |
| 125 | // |
| 126 | //----------------------------------------------------------------------------- |
| 127 | func (c *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) { |
| 128 | e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 129 | err, subDelResp := e2SubDelResp.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 130 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 131 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 132 | } |
| 133 | return subDelResp, nil |
| 134 | } |
| 135 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 136 | func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 137 | e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 138 | err, packedData := e2SubDelResp.Pack(req) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 139 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 140 | return 0, nil, err |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 141 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 142 | return xapp.RIC_SUB_DEL_RESP, packedData, nil |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 143 | } |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 144 | |
| 145 | //----------------------------------------------------------------------------- |
| 146 | // |
| 147 | //----------------------------------------------------------------------------- |
| 148 | func (c *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) { |
| 149 | e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 150 | err, subDelFail := e2SubDelFail.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 151 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 152 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 153 | } |
| 154 | return subDelFail, nil |
| 155 | } |
| 156 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 157 | func (c *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 158 | e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 159 | err, packedData := e2SubDelFail.Pack(req) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 160 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 161 | return 0, nil, err |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 162 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 163 | return xapp.RIC_SUB_DEL_FAILURE, packedData, nil |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 164 | } |