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 | /* |
| 23 | #include <wrapper.h> |
| 24 | |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 25 | #cgo LDFLAGS: -le2ap_wrapper -le2ap |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 26 | */ |
| 27 | import "C" |
| 28 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 29 | import ( |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 30 | "encoding/hex" |
| 31 | "fmt" |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 32 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" |
| 33 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper" |
| 34 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/packer" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 35 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 36 | ) |
| 37 | |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 38 | var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer() |
| 39 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 40 | type E2ap struct { |
| 41 | } |
| 42 | |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 43 | //----------------------------------------------------------------------------- |
| 44 | // |
| 45 | //----------------------------------------------------------------------------- |
| 46 | func (c *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) { |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 47 | e2SubReq := packerif.NewPackerSubscriptionRequest() |
| 48 | packedData := &packer.PackedData{} |
| 49 | packedData.Buf = payload |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 50 | err := e2SubReq.UnPack(packedData) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 51 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 52 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 53 | } |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 54 | err, subReq := e2SubReq.Get() |
| 55 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 56 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 57 | } |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 58 | return subReq, nil |
| 59 | } |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 60 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 61 | func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *packer.PackedData, error) { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 62 | e2SubReq := packerif.NewPackerSubscriptionRequest() |
| 63 | err := e2SubReq.Set(req) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 64 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 65 | return 0, nil, err |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 66 | } |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 67 | err, packedData := e2SubReq.Pack(nil) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 68 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 69 | return 0, nil, err |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 70 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 71 | return xapp.RIC_SUB_REQ, packedData, nil |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | //----------------------------------------------------------------------------- |
| 75 | // |
| 76 | //----------------------------------------------------------------------------- |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 77 | func (c *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) { |
| 78 | e2SubResp := packerif.NewPackerSubscriptionResponse() |
| 79 | packedData := &packer.PackedData{} |
| 80 | packedData.Buf = payload |
| 81 | err := e2SubResp.UnPack(packedData) |
| 82 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 83 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 84 | } |
| 85 | err, subResp := e2SubResp.Get() |
| 86 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 87 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 88 | } |
| 89 | return subResp, nil |
| 90 | } |
| 91 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 92 | func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *packer.PackedData, error) { |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 93 | e2SubResp := packerif.NewPackerSubscriptionResponse() |
| 94 | err := e2SubResp.Set(req) |
| 95 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 96 | return 0, nil, err |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 97 | } |
| 98 | err, packedData := e2SubResp.Pack(nil) |
| 99 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 100 | return 0, nil, err |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 101 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 102 | return xapp.RIC_SUB_RESP, packedData, nil |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | //----------------------------------------------------------------------------- |
| 106 | // |
| 107 | //----------------------------------------------------------------------------- |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 108 | func (c *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) { |
| 109 | e2SubFail := packerif.NewPackerSubscriptionFailure() |
| 110 | packedData := &packer.PackedData{} |
| 111 | packedData.Buf = payload |
| 112 | err := e2SubFail.UnPack(packedData) |
| 113 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 114 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 115 | } |
| 116 | err, subFail := e2SubFail.Get() |
| 117 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 118 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 119 | } |
| 120 | return subFail, nil |
| 121 | } |
| 122 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 123 | func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *packer.PackedData, error) { |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 124 | e2SubFail := packerif.NewPackerSubscriptionFailure() |
| 125 | err := e2SubFail.Set(req) |
| 126 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 127 | return 0, nil, err |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 128 | } |
| 129 | err, packedData := e2SubFail.Pack(nil) |
| 130 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 131 | return 0, nil, err |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 132 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 133 | return xapp.RIC_SUB_FAILURE, packedData, nil |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | //----------------------------------------------------------------------------- |
| 137 | // |
| 138 | //----------------------------------------------------------------------------- |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 139 | func (c *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) { |
| 140 | e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest() |
| 141 | packedData := &packer.PackedData{} |
| 142 | packedData.Buf = payload |
| 143 | err := e2SubDelReq.UnPack(packedData) |
| 144 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 145 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 146 | } |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 147 | err, subDelReq := e2SubDelReq.Get() |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 148 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 149 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 150 | } |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 151 | return subDelReq, nil |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 154 | func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *packer.PackedData, error) { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 155 | e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest() |
| 156 | err := e2SubDelReq.Set(req) |
| 157 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 158 | return 0, nil, err |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 159 | } |
| 160 | err, packedData := e2SubDelReq.Pack(nil) |
| 161 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 162 | return 0, nil, err |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 163 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 164 | return xapp.RIC_SUB_DEL_REQ, packedData, nil |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 167 | //----------------------------------------------------------------------------- |
| 168 | // |
| 169 | //----------------------------------------------------------------------------- |
| 170 | func (c *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) { |
| 171 | e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() |
| 172 | packedData := &packer.PackedData{} |
| 173 | packedData.Buf = payload |
| 174 | err := e2SubDelResp.UnPack(packedData) |
| 175 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 176 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 177 | } |
| 178 | err, subDelResp := e2SubDelResp.Get() |
| 179 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 180 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 181 | } |
| 182 | return subDelResp, nil |
| 183 | } |
| 184 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 185 | func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *packer.PackedData, error) { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 186 | e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() |
| 187 | err := e2SubDelResp.Set(req) |
| 188 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 189 | return 0, nil, err |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 190 | } |
| 191 | err, packedData := e2SubDelResp.Pack(nil) |
| 192 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 193 | return 0, nil, err |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 194 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 195 | return xapp.RIC_SUB_DEL_RESP, packedData, nil |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 196 | } |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 197 | |
| 198 | //----------------------------------------------------------------------------- |
| 199 | // |
| 200 | //----------------------------------------------------------------------------- |
| 201 | func (c *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) { |
| 202 | e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure() |
| 203 | packedData := &packer.PackedData{} |
| 204 | packedData.Buf = payload |
| 205 | err := e2SubDelFail.UnPack(packedData) |
| 206 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 207 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 208 | } |
| 209 | err, subDelFail := e2SubDelFail.Get() |
| 210 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 211 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 212 | } |
| 213 | return subDelFail, nil |
| 214 | } |
| 215 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 216 | func (c *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *packer.PackedData, error) { |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 217 | e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure() |
| 218 | err := e2SubDelFail.Set(req) |
| 219 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 220 | return 0, nil, err |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 221 | } |
| 222 | err, packedData := e2SubDelFail.Pack(nil) |
| 223 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 224 | return 0, nil, err |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 225 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 226 | return xapp.RIC_SUB_DEL_FAILURE, packedData, nil |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 227 | } |