1 /******************************************************************************
3 * Copyright (c) 2020 Intel.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 *******************************************************************************/
20 * @brief XRAN layer one-way delay measurement support
21 * @file xran_delay_measurement.c
22 * @ingroup group_source_xran
23 * @author Intel Corporation
26 #include <immintrin.h>
29 #include <arpa/inet.h>
35 #include <rte_ethdev.h>
38 #include "xran_common.h"
42 #include "xran_lib_mlog_tasks_id.h"
43 #include "xran_ecpri_owd_measurements.h"
45 #include "xran_printf.h"
46 #include "xran_mlog_lnx.h"
48 //#define ORAN_OWD_DEBUG_MSG_FLOW
49 //#define XRAN_OWD_DEBUG_MSG_FLOW
50 //#define XRAN_OWD_DEBUG_DELAY_INFO
51 //#define XRAN_OWD_DEBUG_TIME_STAMPS_INFO
52 //#define XRAN_OWD_DEBUG_MEAS_DB
53 //#define XRAN_OWD_TIMING_MODS
56 // Support for 1-way eCPRI delay measurement per section 3.2.4.6 of eCPRI Specification V2.0
58 uint64_t xran_ptp_to_host(uint64_t compValue)
60 return (rte_be_to_cpu_64(compValue));
62 void xran_host_to_ptp_ts(TimeStamp *ts, struct timespec *t)
64 uint64_t seconds, nanoseconds;
67 nanoseconds = t->tv_nsec%1000000000LL;
68 #ifdef XRAN_OWD_DEBUG_DELAY_CONV_FUNCTIONS
69 printf("H2P_ts tv_sec %8"PRIx64" tv_nsec %8"PRIx64" seconds %8"PRIx64" ns %8"PRIx64" \n",t->tv_sec,t->tv_nsec,seconds,nanoseconds);
72 ts->secs_msb = rte_cpu_to_be_16((rte_be16_t)((seconds >> 32) & 0xFFFF));
73 ts->secs_lsb = rte_cpu_to_be_32((rte_be32_t)(seconds & 0xFFFFFFFF));
74 ts->ns = rte_cpu_to_be_32((rte_be32_t)nanoseconds);
75 #ifdef XRAN_OWD_DEBUG_DELAY_CONV_FUNCTIONS
76 printf("Net order s_msb %4"PRIx16" s_lsb %8"PRIx32" ns %8"PRIx32" \n", ts->secs_msb, ts->secs_lsb,ts->ns );
80 uint64_t xran_ptp_ts_to_ns(TimeStamp *t)
82 uint64_t seconds, nanoseconds;
84 // Convert to host order
85 t->secs_msb=rte_be_to_cpu_16(t->secs_msb);
86 t->secs_lsb=rte_be_to_cpu_32(t->secs_lsb);
87 seconds = ((uint64_t)t->secs_msb << 32) | ((uint64_t)t->secs_lsb );
88 nanoseconds = rte_be_to_cpu_32((uint64_t)t->ns);
89 ret_value = seconds * NS_PER_SEC + nanoseconds;
90 #ifdef XRAN_OWD_DEBUG_DELAY_CONV_FUNCTIONS
91 printf("PTP ts to ns sec_msb %4"PRIx16" secs_lsb %4"PRIx32" ns %4"PRIx32" seconds %8"PRIx64" nanosec %8"PRIx64" ret_value %8"PRIx64"\n",t->secs_msb,t->secs_lsb,t->ns,seconds, nanoseconds,ret_value);
96 static inline uint64_t xran_timespec_to_ns(struct timespec *t)
100 ret_val = t->tv_sec * NS_PER_SEC + t->tv_nsec;
101 #ifdef XRAN_OWD_DEBUG_DELAY_CONV_FUNCTIONS
102 printf("t->tv_sec is %08"PRIx64" tv_nsec is %08"PRIx64" ret_val is %08"PRIx64" ts_to_ns\n",t->tv_sec,t->tv_nsec,ret_val);
108 void xran_ns_to_timespec(uint64_t ns, struct timespec *t)
110 t->tv_sec = ns/NS_PER_SEC;
111 t->tv_nsec = ns % NS_PER_SEC;
115 void xran_initialize_and_verify_owd_pl_length(void* handle)
117 struct xran_device_ctx * p_xran_dev_ctx = (struct xran_device_ctx *)handle;
119 if ((p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id].owdm_PlLength == 0)||(p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id].owdm_PlLength < MIN_OWDM_PL_LENGTH))
121 // Use default length value
122 p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id].owdm_PlLength = MIN_OWDM_PL_LENGTH;
124 else if ( p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id].owdm_PlLength > MAX_OWDM_PL_LENGTH)
126 p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id].owdm_PlLength = MAX_OWDM_PL_LENGTH;
131 void xran_adjust_timing_parameters(void* Handle)
133 struct xran_device_ctx* p_xran_dev_ctx = (struct xran_device_ctx*)Handle;
134 #ifdef XRAN_OWD_TIMING_MODS
135 printf("delayAvg is %d and DELAY_THRESHOLD is %d \n", p_xran_dev_ctx->fh_init.io_cfg.eowd_port[p_xran_dev_ctx->fh_init.io_cfg.id][0].delayAvg, DELAY_THRESHOLD);
137 if (p_xran_dev_ctx->fh_init.io_cfg.eowd_port[p_xran_dev_ctx->fh_init.io_cfg.id][0].delayAvg < DELAY_THRESHOLD )
139 /* Modify the timing parameters */
140 if (p_xran_dev_ctx->fh_cfg.T1a_max_up >= ADJUSTMENT)
141 p_xran_dev_ctx->fh_cfg.T1a_max_up -= ADJUSTMENT;
142 if (p_xran_dev_ctx->fh_cfg.T2a_max_up >= ADJUSTMENT)
143 p_xran_dev_ctx->fh_cfg.T2a_max_up -= ADJUSTMENT;
144 if (p_xran_dev_ctx->fh_cfg.Ta3_min >= ADJUSTMENT)
145 p_xran_dev_ctx->fh_cfg.Ta3_min -= ADJUSTMENT;
146 if (p_xran_dev_ctx->fh_cfg.T1a_max_cp_dl >= ADJUSTMENT)
147 p_xran_dev_ctx->fh_cfg.T1a_max_cp_dl -= ADJUSTMENT;
148 if (p_xran_dev_ctx->fh_cfg.T1a_min_up >= ADJUSTMENT)
149 p_xran_dev_ctx->fh_cfg.T1a_min_up -= ADJUSTMENT;
150 if (p_xran_dev_ctx->fh_cfg.T1a_max_up >= ADJUSTMENT)
151 p_xran_dev_ctx->fh_cfg.T1a_max_up -= ADJUSTMENT;
152 if (p_xran_dev_ctx->fh_cfg.Ta4_min >= ADJUSTMENT)
153 p_xran_dev_ctx->fh_cfg.Ta4_min -= ADJUSTMENT;
154 if (p_xran_dev_ctx->fh_cfg.Ta4_max >= ADJUSTMENT)
155 p_xran_dev_ctx->fh_cfg.Ta4_max -= ADJUSTMENT;
156 #ifdef XRAN_OWD_TIMING_MODS
157 printf("Mod T1a_max_up is %d\n",p_xran_dev_ctx->fh_cfg.T1a_max_up);
158 printf("Mod T2a_max_up is %d\n",p_xran_dev_ctx->fh_cfg.T2a_max_up);
159 printf("Mod Ta3_min is %d\n",p_xran_dev_ctx->fh_cfg.Ta3_min);
160 printf("Mod T1a_max_cp_dl is %d\n",p_xran_dev_ctx->fh_cfg.T1a_max_cp_dl);
161 printf("Mod T1a_min_up is %d\n",p_xran_dev_ctx->fh_cfg.T1a_min_up);
162 printf("Mod T1a_max_up is %d\n",p_xran_dev_ctx->fh_cfg.T1a_max_up);
163 printf("Mod Ta4_min is %d\n",p_xran_dev_ctx->fh_cfg.Ta4_min);
164 printf("Mod Ta4_max is %d\n",p_xran_dev_ctx->fh_cfg.Ta4_max);
172 void xran_compute_and_report_delay_estimate (struct xran_ecpri_del_meas_port *portData, uint16_t totalSamples, uint16_t id )
175 uint64_t *samples= portData->delaySamples;
178 for (i=2 ; i < MX_NUM_SAMPLES; i++) //Ignore first 2 samples
180 portData->delayAvg += samples[i];
184 // Average the delay by the number of samples
185 if ((totalSamples != 0)&&(totalSamples > 2))
187 portData->delayAvg /= (totalSamples-2);
189 // Report Average with printf
191 printf("OWD for port %i is %lu [ns] id %d \n", portData->portid, portData->delayAvg, id);
196 int xran_get_delay_measurements_results (void* handle, uint16_t port_id, uint8_t id, uint64_t* pdelay_avg)
198 int ret_value = FAIL;
199 struct xran_device_ctx* p_xran_dev_ctx = (struct xran_device_ctx*)handle;
200 struct xran_ecpri_del_meas_port* powdp = &p_xran_dev_ctx->fh_init.io_cfg.eowd_port[id][port_id];
201 // Check is the one way delay measurement completed successfully
202 if (powdp->msState == XRAN_OWDM_DONE)
204 *pdelay_avg = powdp->delayAvg;
211 void xran_build_owd_meas_ecpri_hdr(char* mbuf, struct xran_ecpri_del_meas_cmn* eowdcmn)
213 union xran_ecpri_cmn_hdr *tmp= (union xran_ecpri_cmn_hdr*)mbuf;
214 /* Fill common header */
215 tmp->bits.ecpri_ver = XRAN_ECPRI_VER;
216 tmp->bits.ecpri_resv = 0; // should be zero
217 tmp->bits.ecpri_concat = 0;
218 tmp->bits.ecpri_mesg_type = ECPRI_DELAY_MEASUREMENT;
219 tmp->bits.ecpri_payl_size = 10 + eowdcmn->owdm_PlLength;
220 tmp->bits.ecpri_payl_size = rte_cpu_to_be_16(tmp->bits.ecpri_payl_size);
223 void xran_add_at_and_measId_info_to_header(void* pbuf, uint8_t actionType, uint8_t MeasurementID)
225 struct xran_ecpri_delay_meas_pl* tmp = (struct xran_ecpri_delay_meas_pl*)pbuf;
226 // Fill ActionType and MeasurementId
227 tmp->ActionType = actionType;
228 tmp->MeasurementID = MeasurementID;
231 void xran_initialize_ecpri_del_meas_port(struct xran_ecpri_del_meas_cmn* pCmn, struct xran_ecpri_del_meas_port* pPort, uint16_t full)
235 // Initialize port parameters during the first pass
236 pPort->currentMeasID++;
243 pPort->portid = pCmn->measVf;
249 #ifdef XRAN_OWD_DEBUG_MEAS_DB
250 printf("Clearing t1 and delta\n");
253 for (i=0; i < MX_NUM_SAMPLES; i++)
255 pPort->delaySamples[i] = 0;
258 // Set msState based on measMethod and whether the FHI is initiator or recipient
260 if (pCmn->initiator_en)
262 switch (pCmn->measMethod)
265 pPort->msState = XRAN_OWDM_WAITRESP;
268 pPort->msState = XRAN_OWDM_WAITREQ;
271 pPort->msState = XRAN_OWDM_WAITRESP;
273 case XRAN_REM_REQ_WFUP:
274 pPort->msState = XRAN_OWDM_WAITREQWFUP;
277 pPort->msState = XRAN_OWDM_WAITRESP;
283 switch (pCmn->measMethod)
286 pPort->msState = XRAN_OWDM_WAITREQ;
289 pPort->msState = XRAN_OWDM_WAITREMREQ;
292 pPort->msState = XRAN_OWDM_WAITREQWFUP;
294 case XRAN_REM_REQ_WFUP:
295 pPort->msState = XRAN_OWDM_WAITREMREQWFUP;
298 pPort->msState = XRAN_OWDM_WAITREQ;
304 int32_t xran_ecpri_port_update_required (struct xran_io_cfg * cfg, uint16_t port_id)
306 int32_t ret_value = 0;
307 int32_t* port = &cfg->port[0];
312 struct xran_ecpri_del_meas_port* eowdp = &cfg->eowd_port[cfg->id][port_id];
313 struct xran_ecpri_del_meas_cmn* eowdc = &cfg->eowd_cmn[cfg->id];
316 // Check if the current port has completed all the measurements to move to the next port
317 if (eowdp->numMeas == eowdc->numberOfSamples)
319 // Mark state as done and move to the next port
320 if (port_id < cfg->num_vfs)
323 if (port[port_id] == 0xFF)
325 // Done with all ports disable further execution
326 eowdc->owdm_enable = 0;
331 eowdp= &cfg->eowd_port[cfg->id][port_id];
332 // Initialize the next port
333 #ifdef XRAN_OWD_DEBUG_MEAS_DB
334 printf("Init call_1 port %d\n", port_id);
336 xran_initialize_ecpri_del_meas_port(eowdc, eowdp,1);
338 ret_value = 1; // Wait for the next pass through the loop to go to the next port
342 // Disable the measurements
343 eowdc->owdm_enable = 0;
349 // Continue running on the same port
351 // xran_initialize_ecpri_del_meas_port(eowdc, eowdp,0); //Now this logic is driven by the receiver
356 errx(1, "Exit 1 epur with cfg null");
363 * @brief ecpri 2.0 one-way delay measurement transmitter control
365 * @ingroup group_source_xran
370 * Pointer to an xran_device_ctx (cast)
374 * FAIL if failed to process the packet
377 int xran_ecpri_one_way_delay_measurement_transmitter(uint16_t port_id, void* handle)
379 // The ecpri one way delay measurement transmitter handles the transmission
380 // of the owd measurement packets on each of the vfs present in the system in a sequential order
381 // so the owd_meas_method is provided from the configuration file and it can be one of 4 possible
382 // methods: REQUEST, REM_REQ, REQ_WFUP or REM_REQ_WFUP
383 // In the current implementation the measurement is performed on one vf until completion of the number
384 // of measurements defined from the configuration file.
385 // A variable in the xran_ecpri_del_meas_cmn keeps track of the current vf that is using the transmitter and
386 // when the current vf completes all the measurements it moves to the next vf until all of the vfs complete
388 // In the current implementation the measurements start after the xran_if_current_state has reached the
389 // XRAN_RUNNING state (i.e. after having executed the xran_start())
390 // The measurements run only once for the current release.
391 int ret_value = FAIL;
392 struct xran_device_ctx* p_xran_dev_ctx = (struct xran_device_ctx *)handle;
393 struct xran_ecpri_del_meas_cmn* powdc = &p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id];
394 struct xran_ecpri_del_meas_port* powdp = &p_xran_dev_ctx->fh_init.io_cfg.eowd_port[p_xran_dev_ctx->fh_init.io_cfg.id][port_id];
396 if (powdc->measState == OWDMTX_INIT)
398 // Perform the initialization for the very first call to the transmitter for a given port
399 powdc->measVf = port_id;
400 powdc->measState = OWDMTX_ACTIVE;
401 // Check whether PL length was passed in config file and if it is within bounds
402 if ((powdc->owdm_PlLength == 0)|| ( powdc->owdm_PlLength < MIN_OWDM_PL_LENGTH ))
404 // Use default length value
405 powdc->owdm_PlLength = MIN_OWDM_PL_LENGTH;
407 else if ( powdc->owdm_PlLength > MAX_OWDM_PL_LENGTH)
409 powdc->owdm_PlLength = MAX_OWDM_PL_LENGTH;
411 #ifdef XRAN_OWD_DEBUG_MEAS_DB
412 printf("Clear call 2 port_id %d\n", port_id);
414 xran_initialize_ecpri_del_meas_port(powdc, powdp,1);
417 // Initiator State Machine , recipient state machine driven from process_delay_meas()
418 // printf("owdm tx w state %d runMeas %d inen %d\n", powdp->msState,powdp->runMeas,powdc->initiator_en);
420 if ((powdp->runMeas != 0 )&&(powdc->initiator_en != 0)) // Current port still running measurements
422 switch (powdp->msState)
424 case XRAN_OWDM_WAITRESP:
425 // Check the measmethod to define the action
426 if (powdc->measMethod == XRAN_REQUEST)
430 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
431 printf("owdm ecpri tx req gen\n");
433 if (xran_generate_delay_meas(port_id, handle, (uint8_t)ECPRI_REQUEST, powdc->measId) == 0 )
435 errx(1, "Exit 1 owdm tx port_id %d measId %d", port_id, powdc->measId);
442 // The only else corresponds to XRAN_REQ_WFUP
445 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
446 printf("owdm ecpri tx req w fup gen\n");
448 if (xran_generate_delay_meas(port_id, handle, (uint8_t)ECPRI_REQUEST_W_FUP , powdc->measId) == 0 )
450 errx(1, "Exit 2 owdm tx port_id %d measId %d", port_id, powdc->measId );
452 powdp->txDone=0; // Needs fup
456 case XRAN_OWDM_WAITREQ:
459 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
460 printf("owdm ecpri tx rem req gen\n");
462 if (xran_generate_delay_meas(port_id, handle, (uint8_t)ECPRI_REMOTE_REQ , powdc->measId) == 0 )
464 errx(1, "Exit 3 owdm tx port_id %d measId %d", port_id, powdc->measId );
469 case XRAN_OWDM_WAITREQWFUP:
472 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
473 printf("owdm ecpri tx rem req w fup gen\n");
475 if (xran_generate_delay_meas(port_id, handle, (uint8_t)ECPRI_REMOTE_REQ_W_FUP , powdc->measId) == 0 )
477 errx(1, "Exit 4 owdm tx port_id %d measId %d", port_id, powdc->measId );
482 case XRAN_OWDM_GENFUP:
485 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
486 printf("owdm ecpri follow up gen\n");
488 if (xran_generate_delay_meas(port_id, handle, (uint8_t)ECPRI_FOLLOW_UP , powdc->measId) == 0 )
490 errx(1, "Exit 4 owdm tx port_id %d measId %d", port_id, powdc->measId );
495 case XRAN_OWDM_WAITFUP:
498 // Transmitter doesn't have to do anything in these states
501 errx(1, "Exit 5 owdm tx port_id %d measId %d id %d state %d", port_id, powdc->measId, p_xran_dev_ctx->fh_init.io_cfg.id, powdp->msState );
511 * @brief Generate a Delay Measurement packet
512 * Transport layer fragmentation is not supported.
514 * @ingroup group_source_xran
519 * Pointer to an xran_device_ctx (cast)
521 * actionType to be used in the owd measurement packet
522 * @param MeasurementID
523 * MeasurementID to be populated in the owd measurement packet
526 * FAIL if failed to process the packet
529 int xran_generate_delay_meas(uint16_t port_id, void* handle, uint8_t actionType, uint8_t MeasurementID )
531 struct xran_device_ctx* p_xran_dev_ctx = (struct xran_device_ctx *)handle;
533 struct rte_mbuf *mbuf;
535 struct xran_ecpri_delay_meas_pl * pdm= NULL;
536 uint64_t tcv1,tr2m,trm;
537 struct timespec tr2, tr;
538 struct xran_io_cfg* cfg = &p_xran_dev_ctx->fh_init.io_cfg;
539 struct xran_ecpri_del_meas_cmn* powdc = &p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id];
540 struct xran_ecpri_del_meas_port* powdp = &p_xran_dev_ctx->fh_init.io_cfg.eowd_port[p_xran_dev_ctx->fh_init.io_cfg.id][port_id];
541 int32_t *port = &cfg->port[port_id];
542 int ret_value = FAIL;
543 struct rte_ether_addr addr;
544 uint16_t ethertype = ETHER_TYPE_ECPRI;
546 // printf("in xran_generate_delay_meas for action_type %d\n", actionType);
548 pkt_len = sizeof(struct xran_ecpri_del_meas_pkt);
549 // Allocate a buffer from the pool
550 mbuf =xran_ethdi_mbuf_alloc();
554 errx(1,"exit 1 owdm gen");
556 pChar = rte_pktmbuf_append(mbuf, pkt_len);
560 errx(1,"exit 2 owdm gen");
562 pChar = rte_pktmbuf_prepend(mbuf, sizeof(struct rte_ether_hdr));
566 errx(1,"exit 3 owdm gen");
569 struct xran_ethdi_ctx *ctx = xran_ethdi_get_ctx();
571 struct rte_ether_hdr *h = (struct rte_ether_hdr *)rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr*);
572 PANIC_ON(h == NULL, "mbuf prepend of ether_hdr failed");
574 /* Fill in the ethernet header. */
575 rte_eth_macaddr_get(port_id, &h->s_addr); /* set source addr */
577 if (p_xran_dev_ctx->fh_init.io_cfg.id)
579 // rte_ether_addr_copy( (struct rte_ether_addr *)p_xran_dev_ctx->fh_init.p_o_du_addr[port_id],&h->d_addr);
580 h->d_addr = ctx->entities[port_id][ID_O_DU]; /* set dst addr */
584 h->d_addr = ctx->entities[port_id][ID_O_RU]; /* set dst addr */
585 // rte_ether_addr_copy( (struct rte_ether_addr *)p_xran_dev_ctx->fh_init.p_o_ru_addr[port_id],&h->d_addr);
588 h->ether_type = rte_cpu_to_be_16(ethertype); /* ethertype too */
589 mbuf->port = ctx->io_cfg.port[port_id];
592 // Prepare the ecpri header info
593 // Advance pointer to the begining of the ecpri common header
594 pChar = pChar + sizeof (struct rte_ether_hdr);
595 xran_build_owd_meas_ecpri_hdr(pChar, powdc );
596 // Advance pointer to the begining of the xran_ecpri_delay_meas_pl
597 pChar = pChar + sizeof (union xran_ecpri_cmn_hdr);
598 xran_add_at_and_measId_info_to_header(pChar, actionType, MeasurementID);
600 pdm = (struct xran_ecpri_delay_meas_pl *)rte_pktmbuf_mtod_offset(mbuf, struct xran_ecpri_delay_meas_pl *, sizeof(struct rte_ether_hdr) + sizeof(union xran_ecpri_cmn_hdr));
603 // For owd meas originator there are a subset of actionTypes used see ecpri 2.0 Figures 25 and 26 for the details
605 // Record t1, prepare Request Message and determine tcv1 and include both time stamps in the packet
606 // 1) Record the current timestamp when the preparation of the message started i.e. t1
607 if (clock_gettime(CLOCK_REALTIME, &tr )) // t1
611 trm = xran_timespec_to_ns(&tr);
612 #ifdef XRAN_OWD_DEBUG_TIME_STAMPS_INFO
613 printf("trm at gen is %8"PRIx64" \n", trm);
615 // 2) Prepare the delay measurement request packet
616 pdm->ActionType = ECPRI_REQUEST;
617 // 3) Record the current timestamp at the moment that the delay measurement packet is ready to be transmitted tr2 i.e.t1+tcv1 and write it
618 // to the Delay Measurement request packet PL field
619 if (clock_gettime(CLOCK_REALTIME, &tr2 )) // ts
623 // 4) Convert host to ptp time stamp format for tr and write to the outgoing packet
624 xran_host_to_ptp_ts(&pdm->ts, &tr);
625 // 5) Convert from Timestamp tr2 to ns before computing the compensation value
626 tr2m = xran_timespec_to_ns(&tr2);
627 // 6) Compute tcv1 as tr2m-trm
629 #ifdef XRAN_OWD_DEBUG_TIME_STAMPS_INFO
630 printf("tcv1 is %08"PRIx64"\n",tcv1);
633 // 7) write tcv1 to the CompensationValue field of the delay measurement request packet
634 pdm->CompensationValue = rte_cpu_to_be_64(tcv1);
635 #ifdef XRAN_OWD_DEBUG_TIME_STAMPS_INFO
636 printf("compensation value after net order %8"PRIx64" \n", pdm->CompensationValue);
638 // 8) Store t1 and tcv1 to be used later once we get the response message
639 powdp->currentMeasID = pdm->MeasurementID;
642 powdp->msState = XRAN_OWDM_WAITRESP;
643 #ifdef XRAN_OWD_DEBUG_TIME_STAMPS_INFO
644 printf("At req gen t1 %8"PRIx64" and delta %8"PRIx64" port %d \n",powdp->t1,powdp->delta,port_id);
648 case ECPRI_REMOTE_REQ:
649 // Prepare and send Remote Request Message with zero timestamp and correction values
653 // Convert host to ptp time stamp format for tr and write to the outgoing packet
654 xran_host_to_ptp_ts(&pdm->ts, &tr);
655 // write zero to the CompensationValue field of the delay measurement remote request packet
656 pdm->CompensationValue = rte_cpu_to_be_64(tcv1);
657 // 1) Prepare the delay measurement request packet
658 pdm->ActionType = ECPRI_REMOTE_REQ;
659 // 2) Store MeasurementID and msState to be checked once the Request Message is received
660 powdp->currentMeasID = pdm->MeasurementID;
661 powdp->msState = XRAN_OWDM_WAITREQ;
665 case ECPRI_REQUEST_W_FUP:
666 // Record t1, prepare Request with follow up Message and determine tcv1, send zero timestamp and correction value in the packet
667 // 1) Record the current timestamp when the message preparation started i.e. t1
668 if (clock_gettime(CLOCK_REALTIME, &tr )) // t1
672 trm = xran_timespec_to_ns(&tr);
673 // 2) Prepare the delay measurement remote request with follow up packet
674 pdm->ActionType = ECPRI_REQUEST_W_FUP;
675 // 3) Record the current timestamp at the moment that the delay measurement packet is ready to be transmitted tr2 i.e.t1+tcv1
676 if (clock_gettime(CLOCK_REALTIME, &tr2 )) // ts
680 // 4) Convert from Timestamp tr2 to ns before computing the compensation value
681 tr2m = xran_timespec_to_ns(&tr2);
682 // 5) Compute tcv1 as tr2m-trm
684 // Prepare and send Remote Request Message with zero timestamp and correction values
687 powdp->delta = tcv1; // Save tcv1 while waiting for the Response
689 // Convert host to ptp time stamp format for tr and write to the outgoing packet
690 xran_host_to_ptp_ts(&pdm->ts, &tr);
691 // write zero to the CompensationValue field of the delay measurement remote request packet
692 pdm->CompensationValue = rte_cpu_to_be_64(tcv1);
693 // 6) Store MeasurementID and msState to be checked once the Request Message is received
694 powdp->currentMeasID = pdm->MeasurementID;
696 powdp->msState = XRAN_OWDM_GENFUP;
700 case ECPRI_FOLLOW_UP:
701 // Use the t1 and tcv1 values recorded in the ECPRI_REQUEST_W_FUP packet generation step and send these values in the follow up packet
702 // 1) Prepare the delay measurement follow up packet
703 pdm->ActionType = ECPRI_FOLLOW_UP;
704 // 2) Convert t1 from host to ptp format
705 xran_ns_to_timespec(powdp->t1, &tr);
706 // 3) Convert host to ptp time stamp format for tr and write to the outgoing packet
707 xran_host_to_ptp_ts(&pdm->ts, &tr);
708 // 4) write tcv1 to the CompensationValue field of the delay measurement request packet
709 pdm->CompensationValue = rte_cpu_to_be_64(powdp->delta);
710 powdp->currentMeasID = pdm->MeasurementID;
711 powdp->msState = XRAN_OWDM_WAITRESP;
714 case ECPRI_REMOTE_REQ_W_FUP:
715 // Prepare the Remote Request with follow up Message, send zero timestamp and correction value in the packet
719 // Convert host to ptp time stamp format for tr and write to the outgoing packet
720 xran_host_to_ptp_ts(&pdm->ts, &tr);
721 // write zero to the CompensationValue field of the delay measurement remote request packet
722 pdm->CompensationValue = rte_cpu_to_be_64(tcv1);
723 // 1) Prepare the delay measurement request packet
724 pdm->ActionType = ECPRI_REMOTE_REQ_W_FUP;
725 // 2) Store MeasurementID and msState to be checked once the Request Message is received
726 powdp->currentMeasID = pdm->MeasurementID;
727 powdp->msState = XRAN_OWDM_WAITREQWFUP;
732 errx(1,"exit 4 owdm gen");
736 // printf("xran_gen_del_4n");
738 // Retrieve Ethernet Header for the port and copy to the packet
739 rte_eth_macaddr_get(port_id, &addr);
740 #ifdef XRAN_OWD_DEBUG_PKTS
741 printf("id is %d\n", p_xran_dev_ctx->fh_init.io_cfg.id);
742 printf("Port %u SRC MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8
743 " %02"PRIx8" %02"PRIx8" %02"PRIx8"\n",
745 addr.addr_bytes[0], addr.addr_bytes[1], addr.addr_bytes[2],
746 addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5]);
749 if (p_xran_dev_ctx->fh_init.io_cfg.id)
751 #ifdef XRAN_OWD_DEBUG_PKTS
752 int8_t *pa = &p_xran_dev_ctx->fh_init.p_o_du_addr[0];
753 printf("DST_MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", pa[0],pa[1],pa[2],pa[3],pa[4],pa[5]);
755 rte_ether_addr_copy((struct rte_ether_addr *)&p_xran_dev_ctx->fh_init.p_o_du_addr[0], (struct rte_ether_addr *)&h->d_addr.addr_bytes[0]);
760 #ifdef XRAN_OWD_DEBUG_PKTS
761 int8_t *pb = &p_xran_dev_ctx->fh_init.p_o_ru_addr[0];
762 printf("DST_MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", pb[0],pb[1],pb[2],pb[3],pb[4],pb[5]);
764 rte_ether_addr_copy((struct rte_ether_addr *)&p_xran_dev_ctx->fh_init.p_o_ru_addr[0], (struct rte_ether_addr *)&h->d_addr.addr_bytes[0]);
767 #ifdef XRAN_OWD_DEBUG_PKTS
768 uint8_t *pc = &h->s_addr.addr_bytes[0];
769 printf(" Src MAC from packet: %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", pc[0],pc[1],pc[2],pc[3],pc[4],pc[5]);
770 uint8_t *pd = &h->d_addr.addr_bytes[0];
771 printf(" Dst MAC from packet: %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", pd[0],pd[1],pd[2],pd[3],pd[4],pd[5]);
773 // Copy dest address from above
774 // Send out the packet
775 ret_value = rte_eth_tx_burst((uint16_t)*port, 0, &mbuf, 1);
776 // Try using the normal scheme of passing through the ring
777 // ret_value = xran_enqueue_mbuf(mbuf, ctx->tx_ring[port_id]);
778 #ifdef XRAN_OWD_DEBUG_PKTS
779 printf("owdt rte_eth_tx_burst returns %d for port %d\n", ret_value,port_id);
786 * @brief Process a Delay Measurement Request packet
788 * @ingroup group_source_xran
791 * The pointer of the packet buffer to be processed
793 * Pointer to an xran_device_ctx (cast)
794 * @param xran_ecpri_delay_meas_pl
795 * Pointer to an eCPRI delay measurement PL
798 * FAIL if failed to process the packet
800 int xran_process_delmeas_request(struct rte_mbuf *pkt, void* handle, struct xran_ecpri_del_meas_pkt* ptr, uint16_t port_id)
802 int ret_value = FAIL;
804 struct rte_mbuf* pkt1;
806 uint64_t tcv1, tcv2,t2m,trm, td12, t1m;
807 struct xran_ecpri_del_meas_pkt *pdm= NULL;
808 struct timespec tr, t2;
809 struct xran_device_ctx* p_xran_dev_ctx = (struct xran_device_ctx *)handle;
810 struct xran_ecpri_del_meas_cmn* powdc = &p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id];
811 struct xran_ecpri_del_meas_port* powdp = &p_xran_dev_ctx->fh_init.io_cfg.eowd_port[p_xran_dev_ctx->fh_init.io_cfg.id][port_id];
812 struct rte_ether_hdr *eth_hdr;
813 struct rte_ether_addr addr;
814 //struct xran_ethdi_ctx *ctx = xran_ethdi_get_ctx();
816 struct xran_io_cfg* cfg = &p_xran_dev_ctx->fh_init.io_cfg;
817 // struct xran_io_cfg *cfg = &ctx->io_cfg;
818 int32_t *port = &cfg->port[port_id];
820 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
821 printf("RX ecpri Measure Request \n");
823 // Since we are processing the receipt of a delay measurement request packet the following actions
824 // need to be taken (Per eCPRI V2.0 Figure 25)
825 // 1) Record the current timestamp when the message was received i.e. tr
826 if (clock_gettime(CLOCK_REALTIME, &tr )) // tr
828 errx(1, "Exit 1 owd rx f1 port_id %d", port_id);
832 trm = xran_timespec_to_ns(&tr);
833 // 2) Copy MeasurementID to the Delay Measurement Response packet
834 // but first prepend ethernet header since the info is still in the buffer
835 // pchar = rte_pktmbuf_prepend(pkt, (uint16_t)(sizeof(struct rte_ether_hdr)+ sizeof(union xran_ecpri_cmn_hdr ))); // Pointer to new data start address 10/20/20 Now not removing ecpri_cmn in process_delay_meas
836 /*pchar = */rte_pktmbuf_prepend(pkt, (uint16_t)sizeof(struct rte_ether_hdr));
837 pkt1 = rte_pktmbuf_copy(pkt, _eth_mbuf_pool, 0, UINT32_MAX);
838 pdm = (struct xran_ecpri_del_meas_pkt*)rte_pktmbuf_mtod_offset(pkt1, struct xran_ecpri_del_meas_pkt*, sizeof(struct rte_ether_hdr));
839 // 3) Get time stamp T1 from the Timestamp field i.e. t1
840 pt1 = pdm->deMeasPl.ts;
841 // 3a) Convert to ns in the host format
842 t1m = xran_ptp_ts_to_ns(&pt1);
843 // 4) Get the compensation value from the packet i.e. tcv1
844 tcv1 = rte_be_to_cpu_64(pdm->deMeasPl.CompensationValue);
845 // 5) Prepare the delay measurement response packet
846 pdm->deMeasPl.ActionType = ECPRI_RESPONSE;
847 // 6) Record the current timestamp at the moment that the delay measurement packet is ready to be transmitted i.e.t2 and write it
848 // to the Delay Measurement response packet PL field
849 if (clock_gettime(CLOCK_REALTIME, &t2 )) // t2
851 errx(1,"Exit 2 owd rx f1 port_id %d", port_id);
854 // 7) Convert host to ptp time stamp format for t2 and write to the outgoing packet
855 xran_host_to_ptp_ts(&pdm->deMeasPl.ts, &t2);
856 // 8) Convert from Timestamp t2 to ns before computing the compensation value
857 t2m = xran_timespec_to_ns(&t2);
858 // 9) Compute tcv2 as t2-tr
860 // 10) write cv2 to the CompensationValue field of the delay measurement response packet
861 pdm->deMeasPl.CompensationValue = rte_cpu_to_be_64(tcv2);
862 // 11) Fill the ethernet header properly by swapping src and dest addressed from the copied frame
863 eth_hdr = rte_pktmbuf_mtod(pkt1, struct rte_ether_hdr *);
864 /* Swap dest and src mac addresses. */
865 rte_ether_addr_copy(ð_hdr->d_addr, &addr);
866 rte_ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr);
867 rte_ether_addr_copy(&addr, ð_hdr->s_addr);
868 // Still need to check ol_flags state and update if necessary
869 // Compute the delay td12 and save
870 // Still need to define the DB to save the info and run averages
871 td12 = t2m - tcv2 - (t1m + tcv1);
872 // 12) Send the response right away
873 #ifdef XRAN_OWD_DEBUG_PKTS
874 struct rte_ether_hdr *h = (struct rte_ether_hdr *)rte_pktmbuf_mtod(pkt1, struct rte_ether_hdr*);
875 uint8_t *pc = &h->s_addr.addr_bytes[0];
876 printf(" Src MAC from packet: %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", pc[0],pc[1],pc[2],pc[3],pc[4],pc[5]);
877 uint8_t *pd = &h->d_addr.addr_bytes[0];
878 printf(" Dst MAC from packet: %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", pd[0],pd[1],pd[2],pd[3],pd[4],pd[5]);
879 // printf("EtherType: %04"PRIx16" \n",&h->ether_type);
881 pdm = (struct xran_ecpri_del_meas_pkt*)rte_pktmbuf_mtod_offset(pkt1, struct xran_ecpri_del_meas_pkt *, sizeof(struct rte_ether_hdr) );
882 pdm->cmnhdr.bits.ecpri_payl_size = 10 + powdc->owdm_PlLength; // 10 correponds to the xran_ecpri_delay_meas_pl minus the dummy_bytes field which now allows the user to select the length for this field to be sent
883 pdm->cmnhdr.bits.ecpri_payl_size = rte_cpu_to_be_16(pdm->cmnhdr.bits.ecpri_payl_size);
884 pdm->cmnhdr.bits.ecpri_mesg_type = ECPRI_DELAY_MEASUREMENT;
885 #ifdef XRAN_OWD_DEBUG_TIME_STAMPS_INFO
886 printf ("pdm has:%02"PRIx8" %04"PRIx16" %02"PRIx8" %02"PRIx8" \n", pdm->cmnhdr.bits.ecpri_mesg_type, pdm->cmnhdr.bits.ecpri_payl_size, pdm->cmnhdr.bits.ecpri_ver,pdm->deMeasPl.MeasurementID);
889 // Copy dest address from above
890 ret_value = rte_eth_tx_burst((uint16_t)*port, 0, &pkt1, 1); // Need to check for the proper method of getting the port and mac address
891 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
892 printf ("in dly ms req sending response rte_eth_tx_burst returns %d for port %d\n",ret_value, *port);
894 // 13) Update measurements DB and check if completed
895 powdp->delaySamples[powdp->numMeas]= td12 ;
896 #ifdef XRAN_OWD_DEBUG_DELAY_INFO
897 printf("Computed delay is %08"PRIx64" MeasNum %d portId %d id is %d \n",powdp->delaySamples[powdp->numMeas],powdp->numMeas, port_id, p_xran_dev_ctx->fh_init.io_cfg.id);
902 if (powdp->numMeas == powdc->numberOfSamples)
904 xran_compute_and_report_delay_estimate(powdp, powdc->numberOfSamples, p_xran_dev_ctx->fh_init.io_cfg.id);
905 powdp->msState = XRAN_OWDM_DONE;
906 xran_if_current_state = XRAN_RUNNING;
911 // powdp->msState = XRAN_OWDM_IDLE;
912 if (powdc->initiator_en)
914 // Reinitialize txDone for next pass
916 #ifdef XRAN_OWD_DEBUG_MEAS_DB
917 printf("Clear call 3 port id %d \n", port_id);
919 xran_initialize_ecpri_del_meas_port(powdc, powdp,0);
926 int xran_process_delmeas_request_w_fup(struct rte_mbuf *pkt, void* handle, struct xran_ecpri_del_meas_pkt* ptr, uint16_t port_id)
928 int ret_value = FAIL;
930 struct xran_ecpri_del_meas_pkt* pdm= ptr;
932 struct xran_device_ctx* p_xran_dev_ctx = (struct xran_device_ctx *)handle;
933 //struct xran_ecpri_del_meas_cmn* powdc = &p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id];
934 struct xran_ecpri_del_meas_port* powdp = &p_xran_dev_ctx->fh_init.io_cfg.eowd_port[p_xran_dev_ctx->fh_init.io_cfg.id][port_id];
935 //struct xran_ethdi_ctx *const ctx = xran_ethdi_get_ctx();
936 //struct xran_io_cfg *cfg = &ctx->io_cfg;
937 //int32_t* port = &cfg->port[port_id];
939 // Since we are processing the receipt of a delay measurement request with follow up packet the following actions
940 // need to be taken (Per eCPRI V2.0 Figure 26)
941 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
942 printf("RX ecpri Measure Request with fup\n");
945 pdm = (struct xran_ecpri_del_meas_pkt*)rte_pktmbuf_mtod(pkt, struct xran_ecpri_del_meas_pkt*);
946 // Record tr and save to memory with the associated measurement Id and Port
947 // 1) Record the current timestamp when the message was received i.e. tr
948 if (clock_gettime(CLOCK_REALTIME, &tr )) // tr
950 errx(1, "Exit 1 owd rx f2 port_id %d",port_id);
953 trm = xran_timespec_to_ns(&tr);
954 // Save trm so when the Follow Up packet is received we can compute tcv2 as t2-trm
956 // Save the measurement Id
957 powdp->currentMeasID = pdm->deMeasPl.MeasurementID;
958 // Change the state to waiting for follow up
959 powdp->msState = XRAN_OWDM_WAITFUP;
965 int xran_process_delmeas_response(struct rte_mbuf *pkt, void* handle, struct xran_ecpri_del_meas_pkt* ptr, uint16_t port_id)
970 struct xran_ecpri_del_meas_pkt* pdm;
971 //struct timespec t2;
972 struct xran_device_ctx* p_xran_dev_ctx = (struct xran_device_ctx *)handle;
973 struct xran_ecpri_del_meas_cmn* powdc = &p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id];
974 struct xran_ecpri_del_meas_port* powdp = &p_xran_dev_ctx->fh_init.io_cfg.eowd_port[p_xran_dev_ctx->fh_init.io_cfg.id][port_id];
975 //struct xran_ethdi_ctx *const ctx = xran_ethdi_get_ctx();
976 //struct xran_io_cfg *cfg = &ctx->io_cfg;
977 //struct xran_io_cfg* cfg1 = &p_xran_dev_ctx->fh_init.io_cfg;
978 //int32_t* port = &cfg->port[port_id];
981 // Since we are processing the receipt of a delay measurement response packet the following actions
982 // need to be taken (Per eCPRI V2.0 Figure 25)
983 // Need to know if a Remote Request was processed against this measurement ID if so then the receipt of the response
984 // is used to compute the one-way delay as td= (t2-tcv2) - (t1+tcv1) with t2, tcv2 contained in the packet and
985 // t1 and tcv1 stored from the previous Remote Request packet processing task
986 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
987 printf("RX ecpri Measure Response \n");
990 pdm = (struct xran_ecpri_del_meas_pkt*)(struct xran_ecpri_del_meas_pkt *)rte_pktmbuf_mtod(pkt, struct xran_ecpri_del_meas_pkt *);
991 // Save the measurement Id
992 powdp->currentMeasID = pdm->deMeasPl.MeasurementID;
994 // 1) Get time stamp T2 from the Timestamp field i.e. t2
995 pt2 = pdm->deMeasPl.ts;
997 // 2a) Convert to ns in the host format
998 t2m = xran_ptp_ts_to_ns(&pt2);
999 // 3) Get the compensation value from the packet i.e. tcv2
1000 tcv2 = rte_be_to_cpu_64(pdm->deMeasPl.CompensationValue);
1001 #ifdef XRAN_OWD_DEBUG_TIME_STAMPS_INFO
1002 printf ("tcv2 at Gen is %08"PRIx64" \n",tcv2);
1004 // Compute the delay using the stored t1 and tcv1 used in the request message
1005 // td= (t2-tcv2) - (t1+tcv1) where t1 and tcv1 have been stored previously for the same measurement ID
1006 #ifdef XRAN_OWD_DEBUG_TIME_STAMPS_INFO
1007 printf("Delay comp at orig has t2m %08"PRIx64" tcv2 %08"PRIx64" t1 %08"PRIx64" delta %08"PRIx64" port_id %d \n", t2m,tcv2,powdp->t1 ,powdp->delta,port_id);
1009 powdp->delaySamples[powdp->numMeas]= (t2m-tcv2) -(powdp->t1 + powdp->delta);
1010 #ifdef XRAN_OWD_DEBUG_DELAY_INFO
1011 printf("Computed delay is %08"PRIx64" MeasNum %d portId %d id is %d \n",powdp->delaySamples[powdp->numMeas],powdp->numMeas, port_id,p_xran_dev_ctx->fh_init.io_cfg.id );
1018 if (powdp->numMeas == powdc->numberOfSamples)
1020 xran_compute_and_report_delay_estimate(powdp, powdc->numberOfSamples,p_xran_dev_ctx->fh_init.io_cfg.id);
1021 powdp->msState = XRAN_OWDM_DONE;
1022 xran_if_current_state= XRAN_RUNNING;
1027 // powdp->msState = XRAN_OWDM_IDLE;
1028 if (powdc->initiator_en)
1030 // Reinitialize txDone for next pass
1032 #ifdef XRAN_OWD_DEBUG_MEAS_DB
1033 printf("Clear call_4 port_id %d \n", port_id);
1035 xran_initialize_ecpri_del_meas_port(powdc, powdp,0);
1036 #ifdef XRAN_OWD_DEBUG_MEAS_DB
1037 printf("Reseting done \n");
1043 // Needs work and change ret_value to OK
1047 int xran_process_delmeas_rem_request(struct rte_mbuf *pkt, void* handle, struct xran_ecpri_del_meas_pkt* ptr, uint16_t port_id)
1049 int ret_value = FAIL;
1050 struct rte_mbuf* pkt1;
1051 uint64_t tcv1,tr2m,trm;
1052 struct xran_ecpri_del_meas_pkt* pdm;
1054 struct timespec tr2, tr;
1055 struct rte_ether_hdr *eth_hdr;
1056 struct rte_ether_addr addr;
1057 struct xran_device_ctx* p_xran_dev_ctx = (struct xran_device_ctx *)handle;
1058 struct xran_ecpri_del_meas_cmn* powdc = &p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id];
1059 struct xran_ecpri_del_meas_port* powdp = &p_xran_dev_ctx->fh_init.io_cfg.eowd_port[p_xran_dev_ctx->fh_init.io_cfg.id][port_id];
1060 struct xran_ethdi_ctx *const ctx = xran_ethdi_get_ctx();
1061 struct xran_io_cfg *cfg = &ctx->io_cfg;
1062 int32_t* port = &cfg->port[port_id];
1064 // Since we are processing the receipt of a delay measurement remote request packet the following actions
1065 // need to be taken (Per eCPRI V2.0 Figure 25)
1066 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
1067 printf("RX ecpri Measure Remote Request \n");
1070 // 1) Record the current timestamp when the message was received i.e. t1
1071 if (clock_gettime(CLOCK_REALTIME, &tr )) // t1
1073 errx(1,"Exit 1 owd rx f4 port_id %d", port_id);
1076 trm = xran_timespec_to_ns(&tr);
1077 // 2) Copy MeasurementID to the Delay Measurement Request packet
1078 // but first prepend ethernet header since the info is still in the buffer
1079 /*pchar = */rte_pktmbuf_prepend(pkt, (uint16_t)sizeof(struct rte_ether_hdr));
1080 pkt1 = rte_pktmbuf_copy(pkt, _eth_mbuf_pool, 0, UINT32_MAX);
1081 pdm = (struct xran_ecpri_del_meas_pkt*)rte_pktmbuf_mtod_offset(pkt1, struct xran_ecpri_del_meas_pkt*, sizeof(struct rte_ether_hdr));
1083 // 3) Prepare the delay measurement request packet
1084 pdm->deMeasPl.ActionType = ECPRI_REQUEST;
1085 // 4) Record the current timestamp at the moment that the delay measurement packet is ready to be transmitted tr2 i.e.t1+tcv1 and write it
1086 // to the Delay Measurement request packet PL field
1087 if (clock_gettime(CLOCK_REALTIME, &tr2 )) // tr2
1089 errx(1,"Exit 2 owd rx f4 port_id %d", port_id);
1092 // 5) Convert host to ptp time stamp format for tr2 and write to the outgoing packet
1093 xran_host_to_ptp_ts(&pdm->deMeasPl.ts, &tr);
1094 // 6) Convert from Timestamp tr2 to ns before computing the compensation value
1095 tr2m = xran_timespec_to_ns(&tr2);
1096 // 7) Compute tcv1 as tr2m-trm
1098 // 8) write tcv1 to the CompensationValue field of the delay measurement request packet
1099 pdm->deMeasPl.CompensationValue = rte_cpu_to_be_64(tcv1);
1100 // 9) Fill the ethernet header properly by swapping src and dest addressed from the copied frame
1101 eth_hdr = rte_pktmbuf_mtod(pkt1, struct rte_ether_hdr *);
1102 /* Swap dest and src mac addresses. */
1103 rte_ether_addr_copy(ð_hdr->d_addr, &addr);
1104 rte_ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr);
1105 rte_ether_addr_copy(&addr, ð_hdr->s_addr);
1106 // 10) Send the response right away
1107 pdm = (struct xran_ecpri_del_meas_pkt*)rte_pktmbuf_mtod_offset(pkt1, struct xran_ecpri_del_meas_pkt *, sizeof(struct rte_ether_hdr) );
1108 pdm->cmnhdr.bits.ecpri_payl_size = 10 + powdc->owdm_PlLength; // 10 correponds to the xran_ecpri_delay_meas_pl minus the dummy_bytes field which now allows the user to select the length for this field to be sent
1109 pdm->cmnhdr.bits.ecpri_payl_size = rte_cpu_to_be_16(pdm->cmnhdr.bits.ecpri_payl_size);
1110 pdm->cmnhdr.bits.ecpri_mesg_type = ECPRI_DELAY_MEASUREMENT;
1111 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
1112 printf("Ecpri Measure Sending Request Msg \n");
1114 ret_value = rte_eth_tx_burst((uint16_t)*port, 0, &pkt1, 1); // Need to check for the proper method of getting the port and mac address
1115 // Still need to check ol_flags state and update if necessary
1116 // Save the computed delays and the measurementId
1118 powdp->delta = tcv1;
1119 powdp->currentMeasID = pdm->deMeasPl.MeasurementID;
1120 powdp->msState = XRAN_OWDM_WAITRESP;
1125 int xran_process_delmeas_rem_request_w_fup(struct rte_mbuf* pkt, void* handle, struct xran_ecpri_del_meas_pkt* ptr, uint16_t port_id)
1127 int ret_value = FAIL;
1128 struct rte_mbuf* pkt1;
1129 struct rte_mbuf* pkt2;
1130 uint64_t tcv1,tsm,t1;
1131 struct rte_ether_hdr *eth_hdr;
1132 struct rte_ether_addr addr;
1133 struct xran_device_ctx* p_xran_dev_ctx = (struct xran_device_ctx *)handle;
1134 //struct xran_ecpri_del_meas_cmn* powdc = &p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id];
1135 struct xran_ecpri_del_meas_port* powdp = &p_xran_dev_ctx->fh_init.io_cfg.eowd_port[p_xran_dev_ctx->fh_init.io_cfg.id][port_id];
1136 struct xran_ecpri_del_meas_pkt* pdm;
1137 struct timespec tr, ts;
1141 struct xran_ethdi_ctx *const ctx = xran_ethdi_get_ctx();
1142 struct xran_io_cfg *cfg = &ctx->io_cfg;
1143 int32_t* port = &cfg->port[port_id];
1146 // Since we are processing the receipt of a delay measurement remote request with follow up packet the following
1147 // actions need to be taken (Per eCPRI V2.0 Figure 26)
1148 // record t1 for the packet arrival time and then prepare Request with follow up packet which uses 0 for timsetamp
1149 // and for correctionvalue.
1150 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
1151 printf("RX ecpri Measure Remote Request w Fup \n");
1153 // 1) Record the current timestamp when the message was received i.e. t1
1154 if (clock_gettime(CLOCK_REALTIME, &tr )) // t1
1156 errx(1,"Exit 1 owd rx f5 port_id %d", port_id);
1159 t1 = xran_timespec_to_ns(&tr);
1160 // 2) Copy MeasurementID to the Delay Measurement Request packet
1161 // but first prepend ethernet header since the info is still in the buffer
1162 /*pchar = */rte_pktmbuf_prepend(pkt, (uint16_t)sizeof(struct rte_ether_hdr));
1163 pkt1 = rte_pktmbuf_copy(pkt, _eth_mbuf_pool, 0, UINT32_MAX);
1165 pdm = (struct xran_ecpri_del_meas_pkt*)rte_pktmbuf_mtod_offset(pkt1, struct xran_ecpri_del_meas_pkt*, sizeof(struct rte_ether_hdr));
1168 // 3) Prepare the delay measurement request w fup packet
1169 pdm->deMeasPl.ActionType = ECPRI_REQUEST_W_FUP;
1170 // 4) Zero the ts and CompensationValue entries in the packet
1173 // 5) Convert host to ptp time stamp format for t2 and write to the outgoing packet
1174 xran_host_to_ptp_ts(&pdm->deMeasPl.ts, &ts);
1175 // 6) write zero to the CompensationValue field of the delay measurement response packet
1176 pdm->deMeasPl.CompensationValue = rte_cpu_to_be_64(tsm);
1177 // 7) Fill the ethernet header properly by swapping src and dest addressed from the copied frame
1178 eth_hdr = rte_pktmbuf_mtod(pkt1, struct rte_ether_hdr *);
1179 /* Swap dest and src mac addresses. */
1180 rte_ether_addr_copy(ð_hdr->d_addr, &addr);
1181 rte_ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr);
1182 rte_ether_addr_copy(&addr, ð_hdr->s_addr);
1183 // 8) Duplicate packet to be used for the follow up packet
1184 pkt2 = rte_pktmbuf_copy(pkt1, _eth_mbuf_pool, 0, UINT32_MAX);
1185 // 9) Record the current timestamp when the request with follow up is being sent
1186 if (clock_gettime(CLOCK_REALTIME, &ts )) // ts
1188 errx(1,"Exit 2 owd rx f5 port_id %d", port_id);
1191 // 10) Send the request with follow up
1192 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
1193 printf("ecpri Measure sending Request with Fup \n");
1195 ret_value = rte_eth_tx_burst((uint16_t)*port, 0, &pkt1, 1); // Need to check for the proper method of getting the port and mac address
1197 // After the Request with follow up packet has been sent, prepare follow up packet with t1 and tcv1, where
1198 // tcv1 = ts - t1 and writing it to the outgoing packet
1199 pdm = (struct xran_ecpri_del_meas_pkt*)rte_pktmbuf_mtod_offset(pkt2, struct xran_ecpri_del_meas_pkt*, sizeof(struct rte_ether_hdr));
1200 // 11) Prepare the delay measurement request with follow up packet
1201 pdm->deMeasPl.ActionType = ECPRI_FOLLOW_UP;
1202 // 12) Convert host to ptp time stamp format for t1 and write to the outgoing packet
1203 xran_host_to_ptp_ts(&pdm->deMeasPl.ts, &tr);
1204 // 13) Convert from Timestamp t2 to ns before computing the compensation value
1205 tsm = xran_timespec_to_ns(&ts);
1206 // 14) Compute tcv1 as tsm-t1
1208 // 15) write cv1 to the CompensationValue field of the delay measurement response packet
1209 pdm->deMeasPl.CompensationValue = rte_cpu_to_be_64(tcv1);
1211 // 16) Send the follow up message
1212 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
1213 printf("ecpri Measure sending Follow Up \n");
1215 ret_value = rte_eth_tx_burst((uint16_t)*port, 0, &pkt2, 1); // Need to check for the proper method of getting the port and mac address
1217 // Save trm since it will be used to compute tcv2 based on the arrival of the Follow Up packet
1218 powdp->currentMeasID = pdm->deMeasPl.MeasurementID;
1220 powdp->delta = tcv1;
1221 powdp->msState = XRAN_OWDM_WAITRESP;
1227 int xran_process_delmeas_follow_up(struct rte_mbuf *pkt, void* handle, struct xran_ecpri_del_meas_pkt* ptr, uint16_t port_id)
1229 int ret_value = FAIL;
1230 struct rte_mbuf *pkt1;
1231 //char* pChar= NULL;
1232 uint64_t tcv1,tr2m, tcv2, t1;
1233 struct xran_ecpri_del_meas_pkt *pdm;
1234 struct timespec tr2;
1235 struct rte_ether_hdr *eth_hdr;
1236 struct rte_ether_addr addr;
1238 struct xran_device_ctx* p_xran_dev_ctx = (struct xran_device_ctx *)handle;
1239 struct xran_ecpri_del_meas_cmn* powdc = &p_xran_dev_ctx->fh_init.io_cfg.eowd_cmn[p_xran_dev_ctx->fh_init.io_cfg.id];
1240 struct xran_ecpri_del_meas_port* powdp = &p_xran_dev_ctx->fh_init.io_cfg.eowd_port[p_xran_dev_ctx->fh_init.io_cfg.id][port_id];
1241 struct xran_ethdi_ctx *const ctx = xran_ethdi_get_ctx();
1242 struct xran_io_cfg *cfg = &ctx->io_cfg;
1243 int32_t *port = &cfg->port[0];
1244 // Since we are processing the receipt of a delay measurement follow up packet the following actions
1245 // need to be taken (Per eCPRI V2.0 Figure 26)
1246 #ifdef XRAN_OWD_DEBUG_MSG_FLOW
1247 printf("ecpri Measure received Followup \n");
1250 // 1) Record the current timestamp when the message was received i.e. tr2
1251 if (clock_gettime(CLOCK_REALTIME, &tr2 )) // tr2
1253 errx(1,"Exit 1 owd rx f6 port_id %d", port_id);
1256 tr2m = xran_timespec_to_ns(&tr2);
1259 // 2) Copy MeasurementID to the Delay Measurement Response packet
1260 // but first prepend ethernet header since the info is still in the buffer
1261 /*pChar = */rte_pktmbuf_prepend(pkt, (uint16_t)sizeof(struct rte_ether_hdr));
1262 pkt1 = rte_pktmbuf_copy(pkt, _eth_mbuf_pool, 0, UINT32_MAX);
1263 pdm = (struct xran_ecpri_del_meas_pkt*)rte_pktmbuf_mtod_offset(pkt1, struct xran_ecpri_del_meas_pkt*, sizeof(struct rte_ether_hdr));
1265 // 3) Get time stamp T1 from the Timestamp field i.e. t1
1266 pt1 = pdm->deMeasPl.ts;
1267 // 4) Convert to ns in the host format
1268 t1 = xran_ptp_ts_to_ns(&pt1);
1269 // 5) Get the compensation value from the packet i.e. tcv1
1270 tcv1 = rte_be_to_cpu_64(pdm->deMeasPl.CompensationValue);
1272 // 6) Prepare the delay measurement response packet
1273 pdm->deMeasPl.ActionType = ECPRI_RESPONSE;
1275 // 7) Convert host to ptp time stamp format for tr2 and write to the outgoing packet
1276 xran_host_to_ptp_ts(&pdm->deMeasPl.ts, &tr2);
1277 // 8) Convert from Timestamp tr2 to ns before computing the compensation value
1278 tr2m = xran_timespec_to_ns(&tr2);
1279 // 9) Compute tcv2 as tr2m-trm
1280 tcv2 = tr2m - powdp->tr;
1281 // 0) write tcv2 to the CompensationValue field of the delay measurement request packet
1282 pdm->deMeasPl.CompensationValue = rte_cpu_to_be_64(tcv2);
1283 // 9) Fill the ethernet header properly by swapping src and dest addressed from the copied frame
1284 eth_hdr = rte_pktmbuf_mtod(pkt1, struct rte_ether_hdr *);
1285 /* Swap dest and src mac addresses. */
1286 rte_ether_addr_copy(ð_hdr->d_addr, &addr);
1287 rte_ether_addr_copy(ð_hdr->s_addr, ð_hdr->d_addr);
1288 rte_ether_addr_copy(&addr, ð_hdr->s_addr);
1289 pdm = (struct xran_ecpri_del_meas_pkt*)rte_pktmbuf_mtod_offset(pkt1, struct xran_ecpri_del_meas_pkt *, sizeof(struct rte_ether_hdr) );
1290 pdm->cmnhdr.bits.ecpri_payl_size = 10 + powdc->owdm_PlLength; // 10 correponds to the xran_ecpri_delay_meas_pl minus the dummy_bytes field which now allows the user to select the length for this field to be sent
1291 pdm->cmnhdr.bits.ecpri_payl_size = rte_cpu_to_be_16(pdm->cmnhdr.bits.ecpri_payl_size);
1292 pdm->cmnhdr.bits.ecpri_mesg_type = ECPRI_DELAY_MEASUREMENT;
1294 // 10) Send the response right away
1295 ret_value = rte_eth_tx_burst((uint16_t)*port, 0, &pkt1, 1); // Need to check for the proper method of getting the port and mac address
1297 // Compute the delay using the stored t1 and tcv1 used in the request message
1298 // td= (t2-tcv2) - (t1+tcv1) where t1 and tcv1 have been stored previously for the same measurement ID
1299 powdp->delaySamples[powdp->numMeas]= (tr2m-tcv2) -(t1 + tcv1);
1300 #ifdef XRAN_OWD_DEBUG_DELAY_INFO
1301 printf("Computed delay is %08"PRIx64" MeasNum %d portId %d id %d \n",powdp->delaySamples[powdp->numMeas],powdp->numMeas,port_id,p_xran_dev_ctx->fh_init.io_cfg.id);
1305 if (powdp->numMeas == powdc->numberOfSamples)
1307 xran_compute_and_report_delay_estimate(powdp, powdc->numberOfSamples, p_xran_dev_ctx->fh_init.io_cfg.id);
1308 powdp->msState = XRAN_OWDM_DONE;
1309 xran_if_current_state = XRAN_RUNNING;
1314 // powdp->msState = XRAN_OWDM_IDLE;
1315 if (powdc->initiator_en)
1317 // Reinitialize txDone for next pass
1319 #ifdef XRAN_OWD_DEBUG_MEAS_DB
1320 printf("Clear Call_5 port_id %d \n", port_id);
1322 xran_initialize_ecpri_del_meas_port(powdc, powdp,0);
1332 * @brief Parse a Delay Measurement packet
1333 * Transport layer fragmentation is not supported.
1335 * @ingroup group_source_xran
1338 * The pointer of the packet buffer to be parsed
1340 * Pointer to an xran_device_ctx (cast)
1343 * FAIL if failed to process the packet
1345 int process_delay_meas(struct rte_mbuf *pkt, void* handle, uint16_t port_id)
1347 struct xran_device_ctx * p_xran_dev_ctx = (struct xran_device_ctx *)handle;
1348 struct xran_ecpri_del_meas_pkt *ecpri_delmeas_pkt;
1349 //union xran_ecpri_cmn_hdr * ecpricmn;
1350 int ret_value = FAIL;
1351 #ifdef XRAN_OWD_DEBUG_PKTS
1352 printf("pdm Device is %d\n", p_xran_dev_ctx->fh_init.io_cfg.id);
1355 /* Process eCPRI cmn header. */
1356 // (void *)rte_pktmbuf_adj(pkt, sizeof(*ecpricmn));
1357 ecpri_delmeas_pkt = (struct xran_ecpri_del_meas_pkt *)rte_pktmbuf_mtod(pkt, struct xran_ecpri_del_meas_pkt *);
1358 // The processing of the delay measurement here corresponds to eCPRI sections 3.2.4.6.2 and 3.42.6.3
1360 switch(ecpri_delmeas_pkt->deMeasPl.ActionType) {
1362 #ifdef ORAN_OWD_DEBUG_MSG_FLOW
1363 printf("Proc rx Dly Meas Req\n");
1365 ret_value = xran_process_delmeas_request(pkt, p_xran_dev_ctx, ecpri_delmeas_pkt, port_id);
1367 case ECPRI_REQUEST_W_FUP:
1368 #ifdef ORAN_OWD_DEBUG_MSG_FLOW
1369 printf("Proc Dly Meas rx Req w Fup\n");
1371 ret_value = xran_process_delmeas_request_w_fup(pkt, p_xran_dev_ctx, ecpri_delmeas_pkt, port_id);
1373 case ECPRI_RESPONSE:
1374 #ifdef ORAN_OWD_DEBUG_MSG_FLOW
1375 printf("Proc Dly Meas rx Resp\n");
1377 ret_value = xran_process_delmeas_response(pkt, p_xran_dev_ctx, ecpri_delmeas_pkt, port_id);
1379 case ECPRI_REMOTE_REQ:
1380 #ifdef ORAN_OWD_DEBUG_MSG_FLOW
1381 printf("Proc Dly Meas rx Rem Req\n");
1383 ret_value = xran_process_delmeas_rem_request(pkt, p_xran_dev_ctx, ecpri_delmeas_pkt, port_id);
1385 case ECPRI_REMOTE_REQ_W_FUP:
1386 #ifdef ORAN_OWD_DEBUG_MSG_FLOW
1387 printf("Proc Dly Meas Rem rx Req w Fup\n");
1389 ret_value = xran_process_delmeas_rem_request_w_fup(pkt, p_xran_dev_ctx, ecpri_delmeas_pkt, port_id);
1391 case ECPRI_FOLLOW_UP:
1392 #ifdef ORAN_OWD_DEBUG_MSG_FLOW
1393 printf("Proc Dly Meas rx Fup\n");
1395 ret_value = xran_process_delmeas_follow_up(pkt, p_xran_dev_ctx, ecpri_delmeas_pkt, port_id);
1398 #ifdef ORAN_OWD_DEBUG_MSG_FLOW
1399 printf("Proc Dly Meas default\n");