o-du/phy
Intel O-RAN/X-RAN Generated Doxygen Documentation
xran_transport.c
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright (c) 2019 Intel.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *******************************************************************************/
18 
28 #include <stdint.h>
29 #include <endian.h>
30 #include <rte_common.h>
31 #include <rte_config.h>
32 
33 #include "xran_fh_o_du.h"
34 #include "xran_common.h"
35 #include "xran_transport.h"
36 #include "xran_pkt_cp.h"
37 #include "xran_cp_api.h"
38 #include "xran_up_api.h"
39 #include "xran_printf.h"
40 
41 
50 {
51  return(sizeof(struct xran_ecpri_hdr) - sizeof(struct xran_ecpri_cmn_hdr));
52 }
53 
65 uint16_t xran_compose_cid(uint8_t CU_Port_ID, uint8_t BandSector_ID, uint8_t CC_ID, uint8_t Ant_ID)
66 {
67  uint16_t cid;
68  struct xran_eaxcid_config *conf;
69 
70  conf = xran_get_conf_eAxC(NULL);
71 
72  cid = ((CU_Port_ID << conf->bit_cuPortId) & conf->mask_cuPortId)
73  | ((BandSector_ID << conf->bit_bandSectorId) & conf->mask_bandSectorId)
74  | ((CC_ID << conf->bit_ccId) & conf->mask_ccId)
75  | ((Ant_ID << conf->bit_ruPortId) & conf->mask_ruPortId);
76 
77  return (rte_cpu_to_be_16(cid));
78 }
79 
89 void xran_decompose_cid(uint16_t cid, struct xran_eaxc_info *result)
90 {
91  struct xran_eaxcid_config *conf;
92 
93  conf = xran_get_conf_eAxC(NULL);
94  cid = rte_be_to_cpu_16(cid);
95 
96  result->cuPortId = (cid&conf->mask_cuPortId) >> conf->bit_cuPortId;
97  result->bandSectorId = (cid&conf->mask_bandSectorId) >> conf->bit_bandSectorId;
98  result->ccId = (cid&conf->mask_ccId) >> conf->bit_ccId;
99  result->ruPortId = (cid&conf->mask_ruPortId) >> conf->bit_ruPortId;
100 
101  return;
102 }
103 
113 inline void xran_update_ecpri_payload_size(struct rte_mbuf *mbuf, int size)
114 {
115  struct xran_ecpri_hdr *ecpri_hdr;
116 
117  ecpri_hdr = rte_pktmbuf_mtod(mbuf, struct xran_ecpri_hdr *);
118 
119  ecpri_hdr->cmnhdr.ecpri_payl_size = rte_cpu_to_be_16(size);
120 }
121 
122 
142 int xran_build_ecpri_hdr(struct rte_mbuf *mbuf,
143  uint8_t CC_ID, uint8_t Ant_ID,
144  uint8_t seq_id,
145  struct xran_ecpri_hdr **ecpri_hdr)
146 {
147  uint32_t payloadlen;
148  struct xran_ecpri_hdr *tmp;
149 
150 
151  tmp = (struct xran_ecpri_hdr *)rte_pktmbuf_append(mbuf, sizeof(struct xran_ecpri_hdr));
152  if(unlikely(tmp == NULL)) {
153  print_err("Fail to allocate the space for eCPRI hedaer!");
154  return (XRAN_STATUS_RESOURCE);
155  }
156 
157  /* Fill common header */
159  tmp->cmnhdr.ecpri_resv = 0; // should be zero
160  tmp->cmnhdr.ecpri_concat = 0;
162  tmp->ecpri_xtc_id = xran_compose_cid(0, 0, CC_ID, Ant_ID);
163 
164  /* TODO: Transport layer fragmentation is not supported */
165  tmp->ecpri_seq_id.seq_id = seq_id;
166  tmp->ecpri_seq_id.sub_seq_id = 0;
167  tmp->ecpri_seq_id.e_bit = 1;
168 
169  /* Starts with eCPRI header size */
170  payloadlen = xran_get_ecpri_hdr_size();
171 
172  *ecpri_hdr = tmp;
173 
174  return (payloadlen);
175 }
176 
192 int xran_parse_ecpri_hdr(struct rte_mbuf *mbuf,
193  struct xran_ecpri_hdr **ecpri_hdr,
194  struct xran_recv_packet_info *pkt_info)
195 {
196  int ret;
197 
198 
199  *ecpri_hdr = rte_pktmbuf_mtod(mbuf, void *);
200  if(*ecpri_hdr == NULL) {
201  print_err("Invalid packet - eCPRI hedaer!");
203  }
204 
205  /* Process eCPRI header */
206  ret = XRAN_STATUS_SUCCESS;
207  if((*ecpri_hdr)->cmnhdr.ecpri_ver != XRAN_ECPRI_VER) {
208  print_err("Invalid eCPRI version - %d", (*ecpri_hdr)->cmnhdr.ecpri_ver);
210  }
211  if((*ecpri_hdr)->cmnhdr.ecpri_resv != 0) {
212  print_err("Invalid reserved field - %d", (*ecpri_hdr)->cmnhdr.ecpri_resv);
214  }
215 
216  if(pkt_info != NULL) {
217  /* store the information from header */
218  pkt_info->ecpri_version = (*ecpri_hdr)->cmnhdr.ecpri_ver;
219  pkt_info->msg_type = (enum ecpri_msg_type)(*ecpri_hdr)->cmnhdr.ecpri_mesg_type;
220  pkt_info->payload_len = rte_be_to_cpu_16((*ecpri_hdr)->cmnhdr.ecpri_payl_size);
221 
222  pkt_info->seq_id = (*ecpri_hdr)->ecpri_seq_id.seq_id;
223  pkt_info->subseq_id = (*ecpri_hdr)->ecpri_seq_id.sub_seq_id;
224  pkt_info->ebit = (*ecpri_hdr)->ecpri_seq_id.e_bit;
225  xran_decompose_cid((*ecpri_hdr)->ecpri_xtc_id, &(pkt_info->eaxc));
226  }
227 
228  return (ret);
229 }
230 
uint8_t ecpri_concat
Definition: xran_pkt.h:115
This file provides the definition of Control Plane Messages for XRAN Front Haul layer as defined in X...
enum ecpri_msg_type msg_type
#define XRAN_STATUS_SUCCESS
Definition: xran_fh_o_du.h:54
#define XRAN_ECPRI_VER
Definition: xran_pkt.h:61
int xran_build_ecpri_hdr(struct rte_mbuf *mbuf, uint8_t CC_ID, uint8_t Ant_ID, uint8_t seq_id, struct xran_ecpri_hdr **ecpri_hdr)
Build ECPRI header and returns added length.
uint16_t mask_bandSectorId
Definition: xran_fh_o_du.h:310
uint8_t seq_id
Definition: xran_pkt.h:99
uint8_t bandSectorId
uint16_t xran_compose_cid(uint8_t CU_Port_ID, uint8_t BandSector_ID, uint8_t CC_ID, uint8_t Ant_ID)
Compose ecpriRtcid/ecpriPcid.
void xran_decompose_cid(uint16_t cid, struct xran_eaxc_info *result)
Decompose ecpriRtcid/ecpriPcid.
struct xran_eaxcid_config * xran_get_conf_eAxC(void *pHandle)
Get the configuration of eAxC ID.
Definition: xran_main.c:2955
int xran_parse_ecpri_hdr(struct rte_mbuf *mbuf, struct xran_ecpri_hdr **ecpri_hdr, struct xran_recv_packet_info *pkt_info)
Parse ECPRI header.
uint8_t ecpri_ver
Definition: xran_pkt.h:117
uint8_t bit_bandSectorId
Definition: xran_fh_o_du.h:315
#define print_err(fmt, args...)
Definition: xran_printf.h:62
uint8_t ecpri_resv
Definition: xran_pkt.h:116
void xran_update_ecpri_payload_size(struct rte_mbuf *mbuf, int size)
modify the payload size of eCPRI header in xRAN packet
uint8_t e_bit
Definition: xran_pkt.h:101
uint8_t sub_seq_id
Definition: xran_pkt.h:100
Modules provide debug prints and utility functions.
struct xran_ecpri_cmn_hdr cmnhdr
Definition: xran_pkt.h:132
This file provides the definitions for User Plane Messages APIs.
XRAN layer common functionality for both lls-CU and RU as well as C-plane and U-plane.
rte_be16_t ecpri_xtc_id
Definition: xran_pkt.h:133
This file provides public interface to xRAN Front Haul layer implementation as defined in the ORAN-WG...
uint16_t mask_cuPortId
Definition: xran_fh_o_du.h:309
struct ecpri_seq_id ecpri_seq_id
Definition: xran_pkt.h:134
ecpri_msg_type
Definition: xran_pkt.h:75
uint8_t ecpri_mesg_type
Definition: xran_pkt.h:118
uint16_t mask_ruPortId
Definition: xran_fh_o_du.h:312
int xran_get_ecpri_hdr_size(void)
return eCPRI header size without eCPRI common header
#define XRAN_STATUS_RESOURCE
Definition: xran_fh_o_du.h:68
This file provides the definitions for Control Plane Messages APIs.
#define XRAN_STATUS_INVALID_PACKET
Definition: xran_fh_o_du.h:92
uint16_t ecpri_payl_size
Definition: xran_pkt.h:119
struct xran_eaxc_info eaxc
This file provides the definitions for Transport layer (eCPRI) API.