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" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 34 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 35 | ) |
| 36 | |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 37 | var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer() |
| 38 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 39 | type E2ap struct { |
| 40 | } |
| 41 | |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 42 | //----------------------------------------------------------------------------- |
| 43 | // |
| 44 | //----------------------------------------------------------------------------- |
| 45 | func (c *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) { |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 46 | e2SubReq := packerif.NewPackerSubscriptionRequest() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 47 | err, subReq := e2SubReq.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 48 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 49 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 50 | } |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 51 | return subReq, nil |
| 52 | } |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 53 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 54 | func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 55 | e2SubReq := packerif.NewPackerSubscriptionRequest() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 56 | err, packedData := e2SubReq.Pack(req) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 57 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 58 | return 0, nil, err |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 59 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 60 | return xapp.RIC_SUB_REQ, packedData, nil |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | //----------------------------------------------------------------------------- |
| 64 | // |
| 65 | //----------------------------------------------------------------------------- |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 66 | func (c *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) { |
| 67 | e2SubResp := packerif.NewPackerSubscriptionResponse() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 68 | err, subResp := e2SubResp.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 69 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 70 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 71 | } |
| 72 | return subResp, nil |
| 73 | } |
| 74 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 75 | func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 76 | e2SubResp := packerif.NewPackerSubscriptionResponse() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 77 | err, packedData := e2SubResp.Pack(req) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 78 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 79 | return 0, nil, err |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 80 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 81 | return xapp.RIC_SUB_RESP, packedData, nil |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | //----------------------------------------------------------------------------- |
| 85 | // |
| 86 | //----------------------------------------------------------------------------- |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 87 | func (c *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) { |
| 88 | e2SubFail := packerif.NewPackerSubscriptionFailure() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 89 | err, subFail := e2SubFail.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 90 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 91 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 92 | } |
| 93 | return subFail, nil |
| 94 | } |
| 95 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 96 | func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 97 | e2SubFail := packerif.NewPackerSubscriptionFailure() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 98 | err, packedData := e2SubFail.Pack(req) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 99 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 100 | return 0, nil, err |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 101 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 102 | return xapp.RIC_SUB_FAILURE, packedData, nil |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | //----------------------------------------------------------------------------- |
| 106 | // |
| 107 | //----------------------------------------------------------------------------- |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 108 | func (c *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) { |
| 109 | e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 110 | err, subDelReq := e2SubDelReq.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 111 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 112 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 113 | } |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 114 | return subDelReq, nil |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 115 | } |
| 116 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 117 | func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 118 | e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 119 | err, packedData := e2SubDelReq.Pack(req) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 120 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 121 | return 0, nil, err |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 122 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 123 | return xapp.RIC_SUB_DEL_REQ, packedData, nil |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 124 | } |
| 125 | |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 126 | //----------------------------------------------------------------------------- |
| 127 | // |
| 128 | //----------------------------------------------------------------------------- |
| 129 | func (c *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) { |
| 130 | e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 131 | err, subDelResp := e2SubDelResp.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 132 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 133 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 134 | } |
| 135 | return subDelResp, nil |
| 136 | } |
| 137 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 138 | func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 139 | e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 140 | err, packedData := e2SubDelResp.Pack(req) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 141 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 142 | return 0, nil, err |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 143 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 144 | return xapp.RIC_SUB_DEL_RESP, packedData, nil |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 145 | } |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 146 | |
| 147 | //----------------------------------------------------------------------------- |
| 148 | // |
| 149 | //----------------------------------------------------------------------------- |
| 150 | func (c *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) { |
| 151 | e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure() |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 152 | err, subDelFail := e2SubDelFail.UnPack(&e2ap.PackedData{payload}) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 153 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 154 | return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 155 | } |
| 156 | return subDelFail, nil |
| 157 | } |
| 158 | |
Juha Hyttinen | a9bf76c | 2020-02-05 14:06:57 +0200 | [diff] [blame] | 159 | func (c *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *e2ap.PackedData, error) { |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 160 | e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure() |
Juha Hyttinen | 01a4c49 | 2020-02-04 19:29:26 +0200 | [diff] [blame] | 161 | err, packedData := e2SubDelFail.Pack(req) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 162 | if err != nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 163 | return 0, nil, err |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 164 | } |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 165 | return xapp.RIC_SUB_DEL_FAILURE, packedData, nil |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 166 | } |