open-nfapi.oai.patch 71.7 KB
Newer Older
Raymond Knopp's avatar
Raymond Knopp committed
1
diff --git a/nfapi/public_inc/nfapi_interface.h b/nfapi/public_inc/nfapi_interface.h
2
index 2d58c2a..f665d11 100644
Raymond Knopp's avatar
Raymond Knopp committed
3 4 5 6 7 8 9 10 11 12 13
--- a/nfapi/public_inc/nfapi_interface.h
+++ b/nfapi/public_inc/nfapi_interface.h
@@ -1772,7 +1772,7 @@ typedef struct {
 	uint8_t number_of_cc;
 	struct {
 		uint8_t ri_size;
-		uint8_t dl_cqi_pmi_size;
+		uint8_t dl_cqi_pmi_size[8];
 	} cc[NFAPI_MAX_CC];
 } nfapi_ul_config_aperiodic_cqi_pmi_ri_report_t;
 
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
diff --git a/nfapi/src/nfapi.c b/nfapi/src/nfapi.c
index 0e06963..3f017bc 100644
--- a/nfapi/src/nfapi.c
+++ b/nfapi/src/nfapi.c
@@ -823,6 +823,10 @@ uint8_t pack_tlv(uint16_t tag, void *tlv, uint8_t **ppWritePackedMsg, uint8_t *e
 		{
 			NFAPI_TRACE(NFAPI_TRACE_WARN, "Warning pack_tlv tag 0x%x does not match expected 0x%x\n", tl->tag, tag);
 		}
+                else
+                {
+			//NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning pack_tlv tag 0x%x ZERO does not match expected 0x%x\n", tl->tag, tag);
+                }
 	}
 
 	return 1;
diff --git a/nfapi/src/nfapi_p7.c b/nfapi/src/nfapi_p7.c
30
index a3b0141..4083a47 100644
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
--- a/nfapi/src/nfapi_p7.c
+++ b/nfapi/src/nfapi_p7.c
@@ -111,6 +111,8 @@ static uint8_t pack_dl_config_dci_dl_pdu_rel8_value(void* tlv, uint8_t **ppWrite
 {
 	nfapi_dl_config_dci_dl_pdu_rel8_t* value = (nfapi_dl_config_dci_dl_pdu_rel8_t*)tlv;
 	
+        //NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() dci_format:%u\n", __FUNCTION__, value->dci_format);
+
 	return ( push8(value->dci_format, ppWritePackedMsg, end) &&
 			 push8(value->cce_idx, ppWritePackedMsg, end) &&
 			 push8(value->aggregation_level, ppWritePackedMsg, end) &&
@@ -234,6 +236,8 @@ static uint8_t pack_dl_config_bch_pdu_rel8_value(void* tlv, uint8_t **ppWritePac
 {
 	nfapi_dl_config_bch_pdu_rel8_t* value = (nfapi_dl_config_bch_pdu_rel8_t*)tlv;
 	
+        //NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s()\n", __FUNCTION__);
+
 	return( push16(value->length, ppWritePackedMsg, end) &&
 			push16(value->pdu_index, ppWritePackedMsg, end) &&
 			push16(value->transmission_power, ppWritePackedMsg, end));
@@ -545,6 +549,8 @@ static uint8_t pack_dl_config_request_body_value(void* tlv, uint8_t **ppWritePac
 {
 	nfapi_dl_config_request_body_t* value = (nfapi_dl_config_request_body_t*)tlv;
 
+        //NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() dci:%u pdu:%u pdsch:%u rnti:%u pcfich:%u\n", __FUNCTION__, value->number_dci, value->number_pdu, value->number_pdsch_rnti, value->transmission_power_pcfich);
+
 	if(!(push8(value->number_pdcch_ofdm_symbols, ppWritePackedMsg, end) &&
 		 push8(value->number_dci, ppWritePackedMsg, end) &&
 		 push16(value->number_pdu, ppWritePackedMsg, end) &&
@@ -574,6 +580,8 @@ static uint8_t pack_dl_config_request_body_value(void* tlv, uint8_t **ppWritePac
 		{
 			case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE:
 				{
+                                  //NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE\n", __FUNCTION__);
+
 					if(!(pack_tlv(NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG, &pdu->dci_dl_pdu.dci_dl_pdu_rel8, ppWritePackedMsg, end, &pack_dl_config_dci_dl_pdu_rel8_value) &&
 					pack_tlv(NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL9_TAG, &pdu->dci_dl_pdu.dci_dl_pdu_rel9, ppWritePackedMsg, end, &pack_dl_config_dci_dl_pdu_rel9_value) &&
 					pack_tlv(NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL10_TAG, &pdu->dci_dl_pdu.dci_dl_pdu_rel10, ppWritePackedMsg, end, &pack_dl_config_dci_dl_pdu_rel10_value) &&
@@ -587,6 +595,8 @@ static uint8_t pack_dl_config_request_body_value(void* tlv, uint8_t **ppWritePac
 				break;
 			case NFAPI_DL_CONFIG_BCH_PDU_TYPE:
 				{
+                                  //NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() NFAPI_DL_CONFIG_BCH_PDU_TYPE\n", __FUNCTION__);
+
 					if(!(pack_tlv(NFAPI_DL_CONFIG_REQUEST_BCH_PDU_REL8_TAG, &pdu->bch_pdu.bch_pdu_rel8, ppWritePackedMsg, end, &pack_dl_config_bch_pdu_rel8_value)))
 						return 0;
 				}
@@ -684,10 +694,21 @@ static uint8_t pack_dl_config_request(void *msg, uint8_t **ppWritePackedMsg, uin
 {
 	nfapi_dl_config_request_t *pNfapiMsg = (nfapi_dl_config_request_t*)msg;
 	
-	return ( push16(pNfapiMsg->sfn_sf, ppWritePackedMsg, end) &&
-			 pack_tlv(NFAPI_DL_CONFIG_REQUEST_BODY_TAG, &pNfapiMsg->dl_config_request_body, ppWritePackedMsg, end, &pack_dl_config_request_body_value) &&
-			 pack_p7_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config));
+	//return ( push16(pNfapiMsg->sfn_sf, ppWritePackedMsg, end) &&
+			 //pack_tlv(NFAPI_DL_CONFIG_REQUEST_BODY_TAG, &pNfapiMsg->dl_config_request_body, ppWritePackedMsg, end, &pack_dl_config_request_body_value) &&
+			 //pack_p7_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config));
+        { 
+          uint8_t x = push16(pNfapiMsg->sfn_sf, ppWritePackedMsg, end);
+          uint8_t y = pack_tlv(NFAPI_DL_CONFIG_REQUEST_BODY_TAG, &pNfapiMsg->dl_config_request_body, ppWritePackedMsg, end, &pack_dl_config_request_body_value);
+          uint8_t z = pack_p7_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config);
92
 
93 94 95 96
+          if (!x || !y || !z)
+          {
+            NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() NFAPI_DL_CONFIG_REQUEST x:%u y:%u z:%u \n", __FUNCTION__,x,y,z);
+          }
97
+
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
+          return x && y && z;
+        }
 }
 
 static uint8_t pack_ul_config_request_ulsch_rel8_value(void *tlv, uint8_t **ppWritePackedMsg, uint8_t * end)
@@ -1518,7 +1539,21 @@ static uint8_t pack_tx_request_body_value(void* tlv, uint8_t **ppWritePackedMsg,
 		for(j = 0; j < pdu->num_segments; ++j)
 		{
 			// Use -1 as it is unbounded 
-			if(pusharray8(pdu->segments[j].segment_data, (uint32_t)(-1), pdu->segments[j].segment_length, ppWritePackedMsg, end) == 0)
+			// DJP - does not handle -1
+                        // DJP - if(pusharray8(pdu->segments[j].segment_data, (uint32_t)(-1), pdu->segments[j].segment_length, ppWritePackedMsg, end) == 0)
+			int push_ret = pusharray8(pdu->segments[j].segment_data, 65535, pdu->segments[j].segment_length, ppWritePackedMsg, end);
+                        
+                        if (0 && pdu->segments[j].segment_length == 3)
+                        {
+                          NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() BCH? segment_data:%x %x %x\n", __FUNCTION__, 
+                          pdu->segments[j].segment_data[0], 
+                          pdu->segments[j].segment_data[1], 
+                          pdu->segments[j].segment_data[2]
+                          );
+                        }
+                        //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() segment_data:%p segment_length:%u pusharray8()=%d\n", __FUNCTION__, pdu->segments[j].segment_data, pdu->segments[j].segment_length, push_ret);
+
+                        if (push_ret == 0)
 			{
 				return 0;
 			}
@@ -1532,9 +1567,13 @@ static uint8_t pack_tx_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *e
 {
 	nfapi_tx_request_t *pNfapiMsg = (nfapi_tx_request_t*)msg;
 	
-	return ( push16(pNfapiMsg->sfn_sf, ppWritePackedMsg, end) &&
-			 pack_tlv(NFAPI_TX_REQUEST_BODY_TAG, &pNfapiMsg->tx_request_body, ppWritePackedMsg, end, &pack_tx_request_body_value) &&
-			 pack_p7_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config));
+	int x = push16(pNfapiMsg->sfn_sf, ppWritePackedMsg, end);
+        int y = pack_tlv(NFAPI_TX_REQUEST_BODY_TAG, &pNfapiMsg->tx_request_body, ppWritePackedMsg, end, &pack_tx_request_body_value);
+        int z = pack_p7_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config);
+
+        //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() x:%d y:%d z:%d\n", __FUNCTION__, x, y, z);
+
+        return x && y && z;
 }
 
 static uint8_t pack_rx_ue_information_value(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end)
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
@@ -1844,6 +1883,8 @@ static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWriteP
 {
 	nfapi_rx_indication_body_t* value = (nfapi_rx_indication_body_t*)tlv;
 
+        printf("RX ULSCH BODY\n");
+
 	if( push16(value->number_of_pdus, ppWritePackedMsg, end) == 0)
 		return 0;
 
@@ -1851,21 +1892,26 @@ static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWriteP
 	uint16_t i = 0;
 	uint16_t offset = 2; // taking into account the number_of_pdus
 	uint16_t total_number_of_pdus = value->number_of_pdus;
+        printf("ULSCH:pdus:%d\n", total_number_of_pdus);
+
 	for(i = 0; i < total_number_of_pdus; ++i)
 	{
 		nfapi_rx_indication_pdu_t* pdu = &(value->rx_pdu_list[i]);
 		if(pdu->rx_ue_information.tl.tag == NFAPI_RX_UE_INFORMATION_TAG)
 		{
+                  printf("NFAPI_RX_UE_INFORMATION_TAG\n");
 			offset += 4 + 6; 
 		}
 				
 		if(pdu->rx_indication_rel8.tl.tag == NFAPI_RX_INDICATION_REL8_TAG)
 		{
+                  printf("NFAPI_RX_INDICATION_REL8_TAG\n");
 			offset += 4 + 7;
 		}
 
 		if(pdu->rx_indication_rel9.tl.tag == NFAPI_RX_INDICATION_REL9_TAG)
 		{
+                  printf("NFAPI_RX_INDICATION_REL9_TAG\n");
 			offset += 4 + 2;
 		}
 	}
@@ -2592,11 +2638,16 @@ int nfapi_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packedBu
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
 		return -1;
 	}
 
+        if (pMessageHeader->message_id != NFAPI_TIMING_INFO)
+        {
+          //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() message_id:0x%04x phy_id:%u m_segment_sequence:%u timestamp:%u\n", __FUNCTION__, pMessageHeader->message_id, pMessageHeader->phy_id, pMessageHeader->m_segment_sequence, pMessageHeader->transmit_timestamp);
+        }
 	// look for the specific message
 	uint8_t result = 0;
 	switch (pMessageHeader->message_id)
 	{
 		case NFAPI_DL_CONFIG_REQUEST:
+                  //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() NFAPI_DL_CONFIG_REQUEST\n", __FUNCTION__);
 			result = pack_dl_config_request(pMessageHeader, &pWritePackedMessage, end, config);
 			break;
 
196
@@ -2609,6 +2660,7 @@ int nfapi_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packedBu
197 198 199 200 201 202 203
 			break;
 
 		case NFAPI_TX_REQUEST:
+                        //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() NFAPI_TX_REQUEST\n", __FUNCTION__);
 			result = pack_tx_request(pMessageHeader, &pWritePackedMessage, end, config);
 			break;
 
204 205 206 207 208 209 210 211 212
@@ -2621,6 +2673,7 @@ int nfapi_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packedBu
 			break;
 
 		case NFAPI_RX_ULSCH_INDICATION:
+                        printf("RX ULSCH\n");
 			result = pack_rx_ulsch_indication(pMessageHeader, &pWritePackedMessage, end, config);
 			break;
 
@@ -4394,6 +4447,14 @@ static uint8_t unpack_tx_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
 					{
 						if(!pullarray8(ppReadPackedMsg, pdu->segments[0].segment_data, pdu->segments[0].segment_length, pdu->segments[0].segment_length, end))
 							return 0;
+                                                if (0 && pdu->segments[0].segment_length == 3)
+                                                {
+                                                  NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() BCH? segment_data:%x %x %x\n", __FUNCTION__, 
+                                                      pdu->segments[0].segment_data[0], 
+                                                      pdu->segments[0].segment_data[1], 
+                                                      pdu->segments[0].segment_data[2]
+                                                      );
+                                                }
 					}
 					else
 					{
diff --git a/pnf/public_inc/nfapi_pnf_interface.h b/pnf/public_inc/nfapi_pnf_interface.h
228
index f93624d..b25caf2 100644
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
--- a/pnf/public_inc/nfapi_pnf_interface.h
+++ b/pnf/public_inc/nfapi_pnf_interface.h
@@ -319,10 +319,10 @@ typedef struct nfapi_pnf_config
  *  0 will be returned if it fails.
  * 
  * \code
- * nfapi_pnf_config_t* config = nfapi_pnf_config_create();
+ * nfapi_pnf_config_t* config = nfapi_pnf_config_create(void);
  * \endcode
  */
-nfapi_pnf_config_t* nfapi_pnf_config_create();
+nfapi_pnf_config_t* nfapi_pnf_config_create(void);
 
 /*! Delete a pnf configuration 
  * \param config A pointer to a pnf configuraiton
@@ -681,7 +681,7 @@ typedef struct nfapi_pnf_p7_config
 /*! Create and initialise a nfapi_pnf_p7_config structure
  * \return A pointer to a PNF P7 config structure
  */
-nfapi_pnf_p7_config_t* nfapi_pnf_p7_config_create();
+nfapi_pnf_p7_config_t* nfapi_pnf_p7_config_create(void);
 
 /*! Delete an nfapi_pnf_p7_config structure
  * \param config 
diff --git a/pnf/src/pnf.c b/pnf/src/pnf.c
index d6cf364..d0a7fa6 100644
--- a/pnf/src/pnf.c
+++ b/pnf/src/pnf.c
@@ -412,10 +412,10 @@ void pnf_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 	{
 		nfapi_start_request_t req;
 	
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "START.request received\n");
-	
 		nfapi_pnf_config_t* config = &(pnf->_public);
 	
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() START.request received state:%d\n", __FUNCTION__, config->state);
+	
 		// unpack the message
 		if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
diff --git a/pnf/src/pnf_interface.c b/pnf/src/pnf_interface.c
index 74f29a0..7310fc0 100644
--- a/pnf/src/pnf_interface.c
+++ b/pnf/src/pnf_interface.c
@@ -76,6 +76,7 @@ int nfapi_pnf_start(nfapi_pnf_config_t* config)
 
 		sleep(1);
 	}
+	NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() terminate=1 - EXITTING............\n", __FUNCTION__);
 
 	return 0;
 }
@@ -227,7 +228,7 @@ int nfapi_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_start_response_t* res
 	}
 	else
 	{
-		NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: unknow phy id %d\n", __FUNCTION__, resp->header.phy_id);
+		NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: unknown phy id %d\n", __FUNCTION__, resp->header.phy_id);
 		return -1;
 	}
 
diff --git a/pnf/src/pnf_p7.c b/pnf/src/pnf_p7.c
292
index 0fd7828..6d9a332 100644
293 294
--- a/pnf/src/pnf_p7.c
+++ b/pnf/src/pnf_p7.c
295
@@ -25,12 +25,64 @@
296 297 298 299 300 301
 #include <unistd.h>
 #include <errno.h>
 #include <pthread.h>
+#include <stdio.h>
 
 #include "pnf_p7.h"
302 303 304 305
 
 #define FAPI2_IP_DSCP	0
 
-uint32_t get_current_time_hr()
306 307 308
+extern uint16_t sf_ahead;
+//uint16_t sf_ahead=4;
+
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
+void add_sf(uint16_t *frameP, uint16_t *subframeP, int offset)
+{
+    *frameP    = *frameP + ((*subframeP + offset) / 10);
+
+    *subframeP = ((*subframeP + offset) % 10);
+}
+
+void subtract_sf(uint16_t *frameP, uint16_t *subframeP, int offset)
+{
+  if (*subframeP < offset)
+  {
+    *frameP = (*frameP+1024-1)%1024;
+  }
+  *subframeP = (*subframeP+10-offset)%10;
+}
+
+uint16_t sfnsf_add_sf(uint16_t sfnsf, int offset)
+{
+  uint16_t new_sfnsf;
+  uint16_t sfn = NFAPI_SFNSF2SFN(sfnsf);
+  uint16_t sf  = NFAPI_SFNSF2SF(sfnsf);
+
+  //printf("%s() sfn:%u sf:%u\n", __FUNCTION__, sfn, sf);
+  add_sf(&sfn, &sf, offset);
+
+  new_sfnsf = sfn<<4|sf;
+
+  //printf("%s() sfn:%u sf:%u offset:%d sfnsf:%d(DEC:%d) new:%d(DEC:%d)\n", __FUNCTION__, sfn, sf, offset, sfnsf, NFAPI_SFNSF2DEC(sfnsf), new_sfnsf, NFAPI_SFNSF2DEC(new_sfnsf));
+
+  return new_sfnsf;
+}
+
+uint16_t sfnsf_subtract_sf(uint16_t sfnsf, int offset)
+{
+  uint16_t new_sfnsf;
+  uint16_t sfn = NFAPI_SFNSF2SFN(sfnsf);
+  uint16_t sf  = NFAPI_SFNSF2SF(sfnsf);
+
+  //printf("%s() sfn:%u sf:%u\n", __FUNCTION__, sfn, sf);
+  subtract_sf(&sfn, &sf, offset);
+
+  new_sfnsf = sfn<<4|sf;
+
+  //printf("%s() offset:%d sfnsf:%d(DEC:%d) new:%d(DEC:%d)\n", __FUNCTION__, offset, sfnsf, NFAPI_SFNSF2DEC(sfnsf), new_sfnsf, NFAPI_SFNSF2DEC(new_sfnsf));
+
+  return new_sfnsf;
+}
+
357
+uint32_t pnf_get_current_time_hr(void)
358 359 360
 {
 	struct timeval now;
 	(void)gettimeofday(&now, NULL);
361
@@ -64,11 +116,14 @@ void pnf_p7_free(pnf_p7_t* pnf_p7, void* ptr)
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
 // todo : for now these just malloc/free need to move to a memory cache
 nfapi_dl_config_request_t* allocate_nfapi_dl_config_request(pnf_p7_t* pnf_p7) 
 { 
-	return pnf_p7_malloc(pnf_p7, sizeof(nfapi_dl_config_request_t));
+	void *ptr= pnf_p7_malloc(pnf_p7, sizeof(nfapi_dl_config_request_t));
+        //printf("%s() ptr:%p\n", __FUNCTION__, ptr);
+        return ptr;
 }
 
 void deallocate_nfapi_dl_config_request(nfapi_dl_config_request_t* req, pnf_p7_t* pnf_p7) 
 { 
+  //printf("%s() SFN/SF:%d %s req:%p pdu_list:%p\n", __FUNCTION__, NFAPI_SFNSF2DEC(req->sfn_sf), pnf_p7->_public.codec_config.deallocate ? "DEALLOCATE" : "FREE", req, req->dl_config_request_body.dl_config_pdu_list);
 	if(pnf_p7->_public.codec_config.deallocate)
 	{
 		(pnf_p7->_public.codec_config.deallocate)(req->dl_config_request_body.dl_config_pdu_list);
377 378 379 380 381 382 383 384
@@ -77,17 +132,21 @@ void deallocate_nfapi_dl_config_request(nfapi_dl_config_request_t* req, pnf_p7_t
 	{
 		free(req->dl_config_request_body.dl_config_pdu_list);
 	}
+        req->dl_config_request_body.dl_config_pdu_list=0;
 
 	pnf_p7_free(pnf_p7, req);
 }
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
 
 nfapi_ul_config_request_t* allocate_nfapi_ul_config_request(pnf_p7_t* pnf_p7) 
 { 
-	return pnf_p7_malloc(pnf_p7, sizeof(nfapi_ul_config_request_t));
+	void *ptr= pnf_p7_malloc(pnf_p7, sizeof(nfapi_ul_config_request_t));
+        //printf("%s() ptr:%p\n", __FUNCTION__, ptr);
+        return ptr;
 }
 
 void deallocate_nfapi_ul_config_request(nfapi_ul_config_request_t* req, pnf_p7_t* pnf_p7) 
 { 
+  //printf("%s() SFN/SF:%d %s req:%p pdu_list:%p\n", __FUNCTION__, NFAPI_SFNSF2DEC(req->sfn_sf), pnf_p7->_public.codec_config.deallocate ? "DEALLOCATE" : "FREE", req, req->ul_config_request_body.ul_config_pdu_list);
 	if(pnf_p7->_public.codec_config.deallocate)
 	{
 		(pnf_p7->_public.codec_config.deallocate)(req->ul_config_request_body.ul_config_pdu_list);
400 401 402 403 404 405 406 407 408
@@ -96,6 +155,7 @@ void deallocate_nfapi_ul_config_request(nfapi_ul_config_request_t* req, pnf_p7_t
 	{
 		free(req->ul_config_request_body.ul_config_pdu_list);
 	}
+        req->ul_config_request_body.ul_config_pdu_list=0;
 
 	pnf_p7_free(pnf_p7, req);
 }
@@ -107,6 +167,7 @@ nfapi_hi_dci0_request_t* allocate_nfapi_hi_dci0_request(pnf_p7_t* pnf_p7)
409 410 411 412 413 414 415
 
 void deallocate_nfapi_hi_dci0_request(nfapi_hi_dci0_request_t* req, pnf_p7_t* pnf_p7) 
 { 
+  //printf("%s() SFN/SF:%d %s req:%p pdu_list:%p\n", __FUNCTION__, NFAPI_SFNSF2DEC(req->sfn_sf), pnf_p7->_public.codec_config.deallocate ? "DEALLOCATE" : "FREE", req, req->hi_dci0_request_body.hi_dci0_pdu_list);
 	if(pnf_p7->_public.codec_config.deallocate)
 	{
 		(pnf_p7->_public.codec_config.deallocate)(req->hi_dci0_request_body.hi_dci0_pdu_list);
416 417 418 419 420 421 422 423 424
@@ -115,6 +176,7 @@ void deallocate_nfapi_hi_dci0_request(nfapi_hi_dci0_request_t* req, pnf_p7_t* pn
 	{
 		free(req->hi_dci0_request_body.hi_dci0_pdu_list);
 	}
+        req->hi_dci0_request_body.hi_dci0_pdu_list=0;
 
 	pnf_p7_free(pnf_p7, req);
 }
@@ -127,6 +189,9 @@ nfapi_tx_request_t* allocate_nfapi_tx_request(pnf_p7_t* pnf_p7)
425 426 427 428 429 430 431 432 433
 void deallocate_nfapi_tx_request(nfapi_tx_request_t* req, pnf_p7_t* pnf_p7) 
 { 
 	int i = 0;
+
+  //printf("%s() SFN/SF:%d %s req:%p pdu[0]:data:%p\n", __FUNCTION__, NFAPI_SFNSF2DEC(req->sfn_sf), pnf_p7->_public.codec_config.deallocate ? "DEALLOCATE" : "FREE", req, req->tx_request_body.tx_pdu_list[i].segments[0].segment_data);
+
 	for(i = 0; i < req->tx_request_body.number_of_pdus; ++i)
 	{
 		void* data = req->tx_request_body.tx_pdu_list[i].segments[0].segment_data;
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
@@ -139,6 +204,7 @@ void deallocate_nfapi_tx_request(nfapi_tx_request_t* req, pnf_p7_t* pnf_p7)
 		{
 			free(data);
 		}
+                data=0;
 	}
 
 
@@ -150,6 +216,7 @@ void deallocate_nfapi_tx_request(nfapi_tx_request_t* req, pnf_p7_t* pnf_p7)
 	{
 		free(req->tx_request_body.tx_pdu_list);
 	}
+        req->tx_request_body.tx_pdu_list=0;
 
 	pnf_p7_free(pnf_p7, req);
 }
@@ -169,6 +236,7 @@ void deallocate_nfapi_lbt_dl_config_request(nfapi_lbt_dl_config_request_t* req,
 	{
 		free(req->lbt_dl_config_request_body.lbt_dl_config_req_pdu_list);
 	}
+        req->lbt_dl_config_request_body.lbt_dl_config_req_pdu_list=0;
 
 	pnf_p7_free(pnf_p7, req);
 }
@@ -307,11 +375,11 @@ void pnf_p7_rx_reassembly_queue_remove_old_msgs(pnf_p7_t* pnf_p7, pnf_p7_rx_reas
459 460 461 462 463 464 465 466 467 468 469 470 471
 }
 
 
-uint32_t get_sf_time(uint32_t now_hr, uint32_t sf_start_hr)
+static uint32_t get_sf_time(uint32_t now_hr, uint32_t sf_start_hr)
 {
 	if(now_hr < sf_start_hr)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "now is earlier that start of subframe\n");
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "now is earlier than start of subframe now_hr:%u sf_start_hr:%u\n", now_hr, sf_start_hr);
 		return 0;
 	}
 	else
472
@@ -482,29 +550,41 @@ void pnf_pack_and_send_timing_info(pnf_p7_t* pnf_p7)
473 474 475
 
 void send_dummy_subframe(pnf_p7_t* pnf_p7, uint16_t sfn_sf)
 {
476 477 478 479 480
+  struct timespec t;
+  clock_gettime( CLOCK_MONOTONIC, &t);
+
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s(sfn_sf:%d) t:%ld.%09ld\n", __FUNCTION__, NFAPI_SFNSF2DEC(sfn_sf), t.tv_sec, t.tv_nsec);
+
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
+	if(pnf_p7->_public.tx_req && pnf_p7->_public.dummy_subframe.tx_req)
+	{
+		pnf_p7->_public.dummy_subframe.tx_req->sfn_sf = sfn_sf;
+		//NFAPI_TRACE(NFAPI_TRACE_INFO, "Dummy tx_req - enter\n");
+		(pnf_p7->_public.tx_req)(&pnf_p7->_public, pnf_p7->_public.dummy_subframe.tx_req);
+		//NFAPI_TRACE(NFAPI_TRACE_INFO, "Dummy tx_req - exit\n");
+	}
 	if(pnf_p7->_public.dl_config_req && pnf_p7->_public.dummy_subframe.dl_config_req)
 	{
 		pnf_p7->_public.dummy_subframe.dl_config_req->sfn_sf = sfn_sf;
+		//NFAPI_TRACE(NFAPI_TRACE_INFO, "Dummy dl_config_req - enter\n");
 		(pnf_p7->_public.dl_config_req)(&(pnf_p7->_public), pnf_p7->_public.dummy_subframe.dl_config_req);
+		//NFAPI_TRACE(NFAPI_TRACE_INFO, "Dummy dl_config_req - exit\n");
 	}
 	if(pnf_p7->_public.ul_config_req && pnf_p7->_public.dummy_subframe.ul_config_req)
 	{
 		pnf_p7->_public.dummy_subframe.ul_config_req->sfn_sf = sfn_sf;
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "Dummy ul_config_req - enter\n");
 		(pnf_p7->_public.ul_config_req)(&pnf_p7->_public, pnf_p7->_public.dummy_subframe.ul_config_req);
 	}
 	if(pnf_p7->_public.hi_dci0_req && pnf_p7->_public.dummy_subframe.hi_dci0_req)
 	{
 		pnf_p7->_public.dummy_subframe.hi_dci0_req->sfn_sf = sfn_sf;
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "Dummy hi_dci0 - enter\n");
 		(pnf_p7->_public.hi_dci0_req)(&pnf_p7->_public, pnf_p7->_public.dummy_subframe.hi_dci0_req);
 	}
-	if(pnf_p7->_public.tx_req && pnf_p7->_public.dummy_subframe.tx_req)
-	{
-		pnf_p7->_public.dummy_subframe.tx_req->sfn_sf = sfn_sf;
-		(pnf_p7->_public.tx_req)(&pnf_p7->_public, pnf_p7->_public.dummy_subframe.tx_req);
-	}
 	if(pnf_p7->_public.lbt_dl_config_req && pnf_p7->_public.dummy_subframe.lbt_dl_config_req)
 	{
 		pnf_p7->_public.dummy_subframe.lbt_dl_config_req->sfn_sf = sfn_sf;
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "Dummy lbt - enter\n");
 		(pnf_p7->_public.lbt_dl_config_req)(&pnf_p7->_public, pnf_p7->_public.dummy_subframe.lbt_dl_config_req);
 	}
 }
519
@@ -526,10 +606,14 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf)
520
 		return -1;
521 522
 	}
 
523
+#if 1
524 525 526 527 528
 	// save the curren time and sfn_sf
-	pnf_p7->sf_start_time_hr = get_current_time_hr();
+	pnf_p7->sf_start_time_hr = pnf_get_current_time_hr();
 	pnf_p7->sfn_sf = sfn_sf;
 
529
+        uint32_t sfn_sf_tx = sfnsf_add_sf(sfn_sf, sf_ahead);
530 531
+        uint32_t tx_sfn_sf_dec = NFAPI_SFNSF2DEC(sfn_sf_tx);
+
532
 	// If the subframe_buffer has been configured
533 534
 	if(pnf_p7->_public.subframe_buffer_size != 0)
 	{
535
@@ -550,6 +634,10 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf)
536 537 538 539 540 541 542 543 544 545
 			NFAPI_TRACE(NFAPI_TRACE_INFO, "Applying shift %d to sfn/sf (%d -> %d)\n", pnf_p7->sfn_sf_shift, NFAPI_SFNSF2DEC(sfn_sf), shifted_sfn_sf);
 			sfn_sf = shifted_sfn_sf;
 
+                        //
+                        // DJP - why does the shift not apply to pnf_p7->sfn_sf???
+                        //
+
 			pnf_p7->sfn_sf_shift = 0;
 		}
 
546
@@ -558,77 +646,119 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf)
547 548 549
 
 		nfapi_pnf_p7_subframe_buffer_t* subframe_buffer = &(pnf_p7->subframe_buffer[buffer_index]);
 
550 551 552 553 554 555 556 557 558 559 560 561 562
+		uint8_t tx_buffer_index = tx_sfn_sf_dec % pnf_p7->_public.subframe_buffer_size;
+		nfapi_pnf_p7_subframe_buffer_t* tx_subframe_buffer = &(pnf_p7->subframe_buffer[tx_buffer_index]);
+
+                //printf("sfn_sf_dec:%d tx_sfn_sf_dec:%d\n", sfn_sf_dec, tx_sfn_sf_dec);
+
+                if (0) NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() shift:%d subframe_buffer->sfn_sf:%d tx_subframe_buffer->sfn_sf:%d sfn_sf:%d subframe_buffer[buffer_index:%u dl_config_req:%p tx_req:%p] "
+                    "TX:sfn_sf:%d:tx_buffer_index:%d[dl_config_req:%p tx_req:%p]\n", 
+                    __FUNCTION__, 
+                    pnf_p7->sfn_sf_shift, 
+                    NFAPI_SFNSF2DEC(subframe_buffer->sfn_sf), 
+                    NFAPI_SFNSF2DEC(tx_subframe_buffer->sfn_sf), 
+                       sfn_sf_dec,    buffer_index,    subframe_buffer->dl_config_req,    subframe_buffer->tx_req, 
+                    tx_sfn_sf_dec, tx_buffer_index, tx_subframe_buffer->dl_config_req, tx_subframe_buffer->tx_req);
563 564 565 566 567
+
 		// if the subframe buffer sfn sf is set then we have atlease 1 message
 		// from the vnf. 
 		// todo : how to handle the messages we don't have, send dummies for
 		// now
568 569 570 571 572
-		if(subframe_buffer->sfn_sf == sfn_sf)
+
+                //printf("tx_subframe_buffer->sfn_sf:%d sfn_sf_tx:%d\n", tx_subframe_buffer->sfn_sf, sfn_sf_tx);
+                //printf("subframe_buffer->sfn_sf:%d sfn_sf:%d\n", subframe_buffer->sfn_sf, sfn_sf);
+		if(tx_subframe_buffer->sfn_sf == sfn_sf_tx)
573
 		{
574 575 576 577 578
-			if(subframe_buffer->dl_config_req != 0)
+			if(tx_subframe_buffer->tx_req != 0)
 			{
-				if(pnf_p7->_public.dl_config_req)
-					(pnf_p7->_public.dl_config_req)(&(pnf_p7->_public), subframe_buffer->dl_config_req);
579
+				if(pnf_p7->_public.tx_req)
580 581 582
+					(pnf_p7->_public.tx_req)(&(pnf_p7->_public), tx_subframe_buffer->tx_req);
 
-				deallocate_nfapi_dl_config_request(subframe_buffer->dl_config_req, pnf_p7);
583
+				//deallocate_nfapi_tx_request(subframe_buffer->tx_req, pnf_p7);
584 585 586 587 588
 			}
 			else
 			{
 				// send dummy
-				if(pnf_p7->_public.dl_config_req && pnf_p7->_public.dummy_subframe.dl_config_req)
589
+				if(pnf_p7->_public.tx_req && pnf_p7->_public.dummy_subframe.tx_req)
590 591 592 593
 				{
-					pnf_p7->_public.dummy_subframe.dl_config_req->sfn_sf = sfn_sf;
-					(pnf_p7->_public.dl_config_req)(&(pnf_p7->_public), pnf_p7->_public.dummy_subframe.dl_config_req);
+					pnf_p7->_public.dummy_subframe.tx_req->sfn_sf = sfn_sf_tx;
594
+					(pnf_p7->_public.tx_req)(&(pnf_p7->_public), pnf_p7->_public.dummy_subframe.tx_req);
595 596 597 598 599
 				}
 			}
 
-			if(subframe_buffer->ul_config_req != 0)
+			if(tx_subframe_buffer->dl_config_req != 0)
600
 			{
601 602 603 604
-				if(pnf_p7->_public.ul_config_req)
-					(pnf_p7->_public.ul_config_req)(&(pnf_p7->_public), subframe_buffer->ul_config_req);
+				if(pnf_p7->_public.dl_config_req)
+					(pnf_p7->_public.dl_config_req)(&(pnf_p7->_public), tx_subframe_buffer->dl_config_req);
605
 
606
-				deallocate_nfapi_ul_config_request(subframe_buffer->ul_config_req, pnf_p7);
607 608 609 610
+				//deallocate_nfapi_dl_config_request(subframe_buffer->dl_config_req, pnf_p7);
 			}
 			else
 			{
611 612 613 614 615 616 617 618 619
 				// send dummy
-				if(pnf_p7->_public.ul_config_req && pnf_p7->_public.dummy_subframe.ul_config_req)
+				if(pnf_p7->_public.dl_config_req && pnf_p7->_public.dummy_subframe.dl_config_req)
 				{
-					pnf_p7->_public.dummy_subframe.ul_config_req->sfn_sf = sfn_sf;
-					(pnf_p7->_public.ul_config_req)(&(pnf_p7->_public), pnf_p7->_public.dummy_subframe.ul_config_req);
+					pnf_p7->_public.dummy_subframe.dl_config_req->sfn_sf = sfn_sf_tx;
+					(pnf_p7->_public.dl_config_req)(&(pnf_p7->_public), pnf_p7->_public.dummy_subframe.dl_config_req);
 				}
620
 			}
621 622 623
 
-			if(subframe_buffer->hi_dci0_req != 0)
+			if(tx_subframe_buffer->hi_dci0_req != 0)
624 625
 			{
 				if(pnf_p7->_public.hi_dci0_req)
626 627
-					(pnf_p7->_public.hi_dci0_req)(&(pnf_p7->_public), subframe_buffer->hi_dci0_req);
+					(pnf_p7->_public.hi_dci0_req)(&(pnf_p7->_public), tx_subframe_buffer->hi_dci0_req);
628 629 630 631 632 633
 
-				deallocate_nfapi_hi_dci0_request(subframe_buffer->hi_dci0_req, pnf_p7);
+				//deallocate_nfapi_hi_dci0_request(subframe_buffer->hi_dci0_req, pnf_p7);
 			}
 			else
 			{
634 635 636 637 638 639
 				//send dummy
 				if(pnf_p7->_public.hi_dci0_req && pnf_p7->_public.dummy_subframe.hi_dci0_req)
 				{
-					pnf_p7->_public.dummy_subframe.hi_dci0_req->sfn_sf = sfn_sf;
+					pnf_p7->_public.dummy_subframe.hi_dci0_req->sfn_sf = sfn_sf_tx;
 					(pnf_p7->_public.hi_dci0_req)(&(pnf_p7->_public), pnf_p7->_public.dummy_subframe.hi_dci0_req);
640 641 642 643
 				}
 			}
 
-			if(subframe_buffer->tx_req != 0)
644
+                        if(tx_subframe_buffer->dl_config_req != 0)
645
+                        {
646
+                          deallocate_nfapi_dl_config_request(tx_subframe_buffer->dl_config_req, pnf_p7);
647 648
+                          tx_subframe_buffer->dl_config_req = 0;
+                        }
649
+			if(tx_subframe_buffer->tx_req != 0)
650
+                        {
651
+                          deallocate_nfapi_tx_request(tx_subframe_buffer->tx_req, pnf_p7);
652 653
+                          tx_subframe_buffer->tx_req = 0;
+                        }
654
+                        if(tx_subframe_buffer->hi_dci0_req != 0)
655
+                        {
656
+                          deallocate_nfapi_hi_dci0_request(tx_subframe_buffer->hi_dci0_req, pnf_p7);
657 658
+                          tx_subframe_buffer->hi_dci0_req = 0;
+                        }
659
+                }
660 661 662 663 664 665 666
+		else
+		{
+                  // If we ever need to "send" a dummy ul_config this won't work!!!
+                  send_dummy_subframe(pnf_p7, sfn_sf_tx);
+		}
+
+                if(subframe_buffer->sfn_sf == sfn_sf)
667 668 669 670
+		{
+
+			if(subframe_buffer->ul_config_req != 0)
 			{
671 672
-				if(pnf_p7->_public.tx_req)
-					(pnf_p7->_public.tx_req)(&(pnf_p7->_public), subframe_buffer->tx_req);
673 674 675
+				if(pnf_p7->_public.ul_config_req)
+					(pnf_p7->_public.ul_config_req)(&(pnf_p7->_public), subframe_buffer->ul_config_req);
 
676
-				deallocate_nfapi_tx_request(subframe_buffer->tx_req, pnf_p7);
677 678 679 680 681
+				//deallocate_nfapi_ul_config_request(subframe_buffer->ul_config_req, pnf_p7);
 			}
 			else
 			{
 				// send dummy
682
-				if(pnf_p7->_public.tx_req && pnf_p7->_public.dummy_subframe.tx_req)
683 684
+				if(pnf_p7->_public.ul_config_req && pnf_p7->_public.dummy_subframe.ul_config_req)
 				{
685 686
-					pnf_p7->_public.dummy_subframe.tx_req->sfn_sf = sfn_sf;
-					(pnf_p7->_public.tx_req)(&(pnf_p7->_public), pnf_p7->_public.dummy_subframe.tx_req);
687 688 689 690 691
+					pnf_p7->_public.dummy_subframe.ul_config_req->sfn_sf = sfn_sf;
+					(pnf_p7->_public.ul_config_req)(&(pnf_p7->_public), pnf_p7->_public.dummy_subframe.ul_config_req);
 				}
 			}
 
692
@@ -637,7 +767,7 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf)
693 694 695 696 697 698 699 700
 				if(pnf_p7->_public.lbt_dl_config_req)
 					(pnf_p7->_public.lbt_dl_config_req)(&(pnf_p7->_public), subframe_buffer->lbt_dl_config_req);
 
-				deallocate_nfapi_lbt_dl_config_request(subframe_buffer->lbt_dl_config_req, pnf_p7);
+				//deallocate_nfapi_lbt_dl_config_request(subframe_buffer->lbt_dl_config_req, pnf_p7);
 			}
 			else
 			{
701
@@ -650,14 +780,35 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf)
702 703 704
 
 			}
 
705 706 707
-			memset(&(pnf_p7->subframe_buffer[buffer_index]), 0, sizeof(nfapi_pnf_p7_subframe_buffer_t));
-			pnf_p7->subframe_buffer[buffer_index].sfn_sf = -1;
-		}
708 709 710
-		else
-		{
-			send_dummy_subframe(pnf_p7, sfn_sf);
711 712 713 714
+                        //if(subframe_buffer->dl_config_req != 0)
+                          //deallocate_nfapi_dl_config_request(subframe_buffer->dl_config_req, pnf_p7);
+			//if(subframe_buffer->tx_req != 0)
+                          //deallocate_nfapi_tx_request(subframe_buffer->tx_req, pnf_p7);
715
+                        if(subframe_buffer->ul_config_req != 0)
716
+                        {
717
+                          deallocate_nfapi_ul_config_request(subframe_buffer->ul_config_req, pnf_p7);
718 719 720
+                          subframe_buffer->ul_config_req = 0;
+
+                        }
721 722
+                        //if(subframe_buffer->hi_dci0_req != 0)
+                          //deallocate_nfapi_hi_dci0_request(subframe_buffer->hi_dci0_req, pnf_p7);
723
+			if(subframe_buffer->lbt_dl_config_req != 0)
724
+                        {
725
+                          deallocate_nfapi_lbt_dl_config_request(subframe_buffer->lbt_dl_config_req, pnf_p7);
726 727 728 729 730 731 732 733
+                          subframe_buffer->lbt_dl_config_req = 0;
+                        }
+                } // sfn_sf match
+
+                if (subframe_buffer->dl_config_req == 0 && subframe_buffer->tx_req == 0 && subframe_buffer->ul_config_req == 0 && subframe_buffer->lbt_dl_config_req == 0)
+                {
+                  memset(&(pnf_p7->subframe_buffer[buffer_index]), 0, sizeof(nfapi_pnf_p7_subframe_buffer_t));
+                  pnf_p7->subframe_buffer[buffer_index].sfn_sf = -1;
734 735
 		}
 
736 737 738 739 740 741 742
+                //printf("pnf_p7->_public.timing_info_mode_periodic:%d pnf_p7->timing_info_period_counter:%d pnf_p7->_public.timing_info_period:%d\n", pnf_p7->_public.timing_info_mode_periodic, pnf_p7->timing_info_period_counter, pnf_p7->_public.timing_info_period);
+                //printf("pnf_p7->_public.timing_info_mode_aperiodic:%d pnf_p7->timing_info_aperiodic_send:%d\n", pnf_p7->_public.timing_info_mode_aperiodic, pnf_p7->timing_info_aperiodic_send);
+                //printf("pnf_p7->timing_info_ms_counter:%d\n", pnf_p7->timing_info_ms_counter);
+
 		// send the periodic timing info if configured
 		if(pnf_p7->_public.timing_info_mode_periodic && (pnf_p7->timing_info_period_counter++) == pnf_p7->_public.timing_info_period)
 		{
743
@@ -678,14 +829,15 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf)
744 745 746 747 748 749 750 751 752
 	}
 	else
 	{
-		send_dummy_subframe(pnf_p7, sfn_sf);
+		//send_dummy_subframe(pnf_p7, sfn_sf_tx);
 	}
 
 
+        //printf("pnf_p7->tick:%d\n", pnf_p7->tick);
753 754 755 756 757 758 759 760
 	if(pnf_p7->tick == 1000)
 	{
 
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF P7:%d] DL:(%d/%d) UL:(%d/%d) HI:(%d/%d) TX:(%d/%d)\n", pnf_p7->_public.phy_id,
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF P7:%d] (ONTIME/LATE) DL:(%d/%d) UL:(%d/%d) HI:(%d/%d) TX:(%d/%d)\n", pnf_p7->_public.phy_id,
 					pnf_p7->stats.dl_conf_ontime, pnf_p7->stats.dl_conf_late, 
 					pnf_p7->stats.ul_conf_ontime, pnf_p7->stats.ul_conf_late, 
 					pnf_p7->stats.hi_dci0_ontime, pnf_p7->stats.hi_dci0_late, 
761
@@ -694,6 +846,7 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf)
762 763 764 765 766 767 768
 		memset(&pnf_p7->stats, 0, sizeof(pnf_p7->stats));
 	}
 	pnf_p7->tick++;
+#endif
 
 	if(pthread_mutex_unlock(&(pnf_p7->mutex)) != 0)
 	{
769
@@ -724,7 +877,7 @@ uint8_t is_p7_request_in_window(uint16_t sfnsf, const char* name, pnf_p7_t* phy)
770 771 772 773 774 775 776 777
 			if(recv_sfn_sf_dec > ((current_sfn_sf_dec + timing_window) % NFAPI_MAX_SFNSFDEC))
 			{
 				// out of window
-				//NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is late %d (with wrap)\n", current_sfn_sf_dec, name, recv_sfn_sf_dec);
+				NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is late %d (with wrap)\n", current_sfn_sf_dec, name, recv_sfn_sf_dec);
 			}
 			else
 			{
778
@@ -736,7 +889,7 @@ uint8_t is_p7_request_in_window(uint16_t sfnsf, const char* name, pnf_p7_t* phy)
779 780 781 782 783 784 785 786
 		else
 		{
 			// too late
-			//NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in late %d (%d)\n", current_sfn_sf_dec, name, recv_sfn_sf_dec, (current_sfn_sf_dec - recv_sfn_sf_dec));
+			NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in late %d (delta:%d)\n", current_sfn_sf_dec, name, recv_sfn_sf_dec, (current_sfn_sf_dec - recv_sfn_sf_dec));
 		}
 
 	}
787
@@ -751,8 +904,8 @@ uint8_t is_p7_request_in_window(uint16_t sfnsf, const char* name, pnf_p7_t* phy)
788 789 790 791 792 793 794 795 796 797
 		}
 		else
 		{
-			// to far in the future
-			//NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is out of window %d (%d) [%d]\n", current_sfn_sf_dec, name, recv_sfn_sf_dec,  (recv_sfn_sf_dec - current_sfn_sf_dec), timing_window);
+			// too far in the future
+			NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is out of window %d (delta:%d) [max:%d]\n", current_sfn_sf_dec, name, recv_sfn_sf_dec,  (recv_sfn_sf_dec - current_sfn_sf_dec), timing_window);
 		}
 
 	}
798
@@ -785,15 +938,32 @@ void pnf_handle_dl_config_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
 			return;
 		}
 
-		if(is_p7_request_in_window(req->sfn_sf, "dl_config_request", pnf_p7))
-		{
-			uint32_t sfn_sf_dec = NFAPI_SFNSF2DEC(req->sfn_sf);
-			uint8_t buffer_index = sfn_sf_dec % pnf_p7->_public.subframe_buffer_size;
+                if (
+                    0 && 
+                    (NFAPI_SFNSF2DEC(req->sfn_sf) % 100 ==0 ||
+                     NFAPI_SFNSF2DEC(req->sfn_sf) % 105 ==0 
+                    )
+                )
+                  NFAPI_TRACE(NFAPI_TRACE_INFO, "DL_CONFIG.req sfn_sf:%d pdcch:%u dci:%u pdu:%u pdsch_rnti:%u pcfich:%u\n", 
+                      NFAPI_SFNSF2DEC(req->sfn_sf),
+                      req->dl_config_request_body.number_pdcch_ofdm_symbols,
+                      req->dl_config_request_body.number_dci,
+                      req->dl_config_request_body.number_pdu,
+                      req->dl_config_request_body.number_pdsch_rnti,
+                      req->dl_config_request_body.transmission_power_pcfich
+                      );
+
+                if(is_p7_request_in_window(req->sfn_sf, "dl_config_request", pnf_p7))
+                {
+                  uint32_t sfn_sf_dec = NFAPI_SFNSF2DEC(req->sfn_sf);
+                  uint8_t buffer_index = sfn_sf_dec % pnf_p7->_public.subframe_buffer_size;
825
+
826
+                  printf("%s() POPULATE DL_CONFIG_REQ sfn_sf:%d buffer_index:%d\n", __FUNCTION__, sfn_sf_dec, buffer_index);
827 828 829 830 831 832 833 834 835
 
 			// if there is already an dl_config_req make sure we free it.
 			if(pnf_p7->subframe_buffer[buffer_index].dl_config_req != 0)
 			{
-				NFAPI_TRACE(NFAPI_TRACE_NOTE, "HERE HERE HERE\n");
+				NFAPI_TRACE(NFAPI_TRACE_NOTE, "%s() is_p7_request_in_window()=TRUE buffer_index occupied - free it first sfn_sf:%d buffer_index:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(req->sfn_sf), buffer_index);
 				//NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] Freeing dl_config_req at index %d (%d/%d)", 
 				//			pMyPhyInfo->sfnSf, bufferIdx,
 				//			SFNSF2SFN(dreq->sfn_sf), SFNSF2SF(dreq->sfn_sf));
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
@@ -860,6 +1030,8 @@ void pnf_handle_ul_config_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_
 			uint32_t sfn_sf_dec = NFAPI_SFNSF2DEC(req->sfn_sf);
 			uint8_t buffer_index = sfn_sf_dec % pnf_p7->_public.subframe_buffer_size;
 
+                        printf("%s() POPULATE UL_CONFIG_REQ sfn_sf:%d buffer_index:%d\n", __FUNCTION__, sfn_sf_dec, buffer_index);
+
 			if(pnf_p7->subframe_buffer[buffer_index].ul_config_req != 0)
 			{
 				//NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] Freeing ul_config_req at index %d (%d/%d)", 
@@ -876,7 +1048,7 @@ void pnf_handle_ul_config_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_
 		}
 		else
 		{
-			//NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] NOT storing ul_config_req SFN/SF %d/%d\n", pMyPhyInfo->sfnSf, SFNSF2SFN(req->sfn_sf), SFNSF2SF(req->sfn_sf));
+			NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] NOT storing ul_config_req OUTSIDE OF TRANSMIT BUFFER WINDOW SFN/SF %d\n", NFAPI_SFNSF2DEC(pnf_p7->sfn_sf), NFAPI_SFNSF2DEC(req->sfn_sf));
 			deallocate_nfapi_ul_config_request(req, pnf_p7);
 
 			if(pnf_p7->_public.timing_info_mode_aperiodic)
@@ -994,6 +1166,16 @@ void pnf_handle_tx_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7)
855 856 857
 			uint32_t sfn_sf_dec = NFAPI_SFNSF2DEC(req->sfn_sf);
 			uint8_t buffer_index = sfn_sf_dec % pnf_p7->_public.subframe_buffer_size;
 
858 859 860 861
+                        struct timespec t;
+                        clock_gettime(CLOCK_MONOTONIC, &t);
+
+                        printf("%s() %ld.%09ld POPULATE TX_REQ sfn_sf:%d buffer_index:%d\n", __FUNCTION__, t.tv_sec, t.tv_nsec, sfn_sf_dec, buffer_index);
862
+
863 864 865 866 867 868 869 870
+                        if (0 && NFAPI_SFNSF2DEC(req->sfn_sf)%100==0) NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() TX_REQ.req sfn_sf:%d pdus:%d - TX_REQ is within window\n",
+                            __FUNCTION__,
+                            NFAPI_SFNSF2DEC(req->sfn_sf),
+                            req->tx_request_body.number_of_pdus);
+
 			if(pnf_p7->subframe_buffer[buffer_index].tx_req != 0)
 			{
 				//NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] Freeing tx_req at index %d (%d/%d)", 
871
@@ -1010,6 +1192,8 @@ void pnf_handle_tx_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7)
872 873 874 875 876 877 878 879
 		}
 		else
 		{
+                  printf("%s() TX_REQUEST Request is outside of window REQ:SFN_SF:%d CURR:SFN_SF:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(req->sfn_sf), NFAPI_SFNSF2DEC(pnf_p7->sfn_sf));
+
 			deallocate_nfapi_tx_request(req, pnf_p7);
 
 			if(pnf_p7->_public.timing_info_mode_aperiodic)
880
@@ -1126,12 +1310,27 @@ uint32_t calculate_t2(uint32_t now_time_hr, uint16_t sfn_sf, uint32_t sf_start_t
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
 	uint32_t sf_time_us = get_sf_time(now_time_hr, sf_start_time_hr);
 	uint32_t t2 = (NFAPI_SFNSF2DEC(sfn_sf) * 1000) + sf_time_us;
 
+        if (0)
+        {
+          static uint32_t prev_t2 = 0;
+
+          NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s(now_time_hr:%u sfn_sf:%d sf_start_time_Hr:%u) sf_time_us:%u t2:%u prev_t2:%u diff:%u\n",
+              __FUNCTION__,
+              now_time_hr, NFAPI_SFNSF2DEC(sfn_sf), sf_start_time_hr,
+              sf_time_us,
+              t2,
+              prev_t2,
+              t2-prev_t2);
+
+          prev_t2 = t2;
+        }
+
 	return t2;
 }
 
 uint32_t calculate_t3(uint16_t sfn_sf, uint32_t sf_start_time_hr)
 {
-	uint32_t now_time_hr = get_current_time_hr();
+	uint32_t now_time_hr = pnf_get_current_time_hr();
 
 	uint32_t sf_time_us = get_sf_time(now_time_hr, sf_start_time_hr);
 
909
@@ -1391,6 +1590,8 @@ void pnf_nfapi_p7_read_dispatch_message(pnf_p7_t* pnf_p7, uint32_t now_hr_time)
910 911 912 913 914 915 916 917
 			// read the segment
 			recvfrom_result = recvfrom(pnf_p7->p7_sock, pnf_p7->rx_message_buffer, header.message_length, MSG_DONTWAIT, (struct sockaddr*)&remote_addr, &remote_addr_size);
 
+		now_hr_time = pnf_get_current_time_hr(); //DJP - moved to here - get closer timestamp???
+
 			if(recvfrom_result > 0)
 			{
 				pnf_handle_p7_message(pnf_p7->rx_message_buffer, recvfrom_result, pnf_p7, now_hr_time);
918
@@ -1417,7 +1618,10 @@ void pnf_nfapi_p7_read_dispatch_message(pnf_p7_t* pnf_p7, uint32_t now_hr_time)
919 920 921 922 923 924 925 926 927 928 929
 
 		// need to update the time as we would only use the value from the
 		// select
-		now_hr_time = get_current_time_hr();
+#if 0
+// DJP - why do this here and not on return from recv???
+		now_hr_time = pnf_get_current_time_hr();
+#endif
 	}
 	while(recvfrom_result > 0);
 }
930
@@ -1512,7 +1716,7 @@ int pnf_p7_message_pump(pnf_p7_t* pnf_p7)
931 932 933 934 935 936 937 938
 
 		selectRetval = select(pnf_p7->p7_sock+1, &rfds, NULL, NULL, &timeout);
 
-		uint32_t now_hr_time = get_current_time_hr();
+		uint32_t now_hr_time = pnf_get_current_time_hr();
 
 		if(selectRetval == 0)
 		{	
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
diff --git a/pnf_sim/src/main.cpp b/pnf_sim/src/main.cpp
index 38767d8..e2622cf 100644
--- a/pnf_sim/src/main.cpp
+++ b/pnf_sim/src/main.cpp
@@ -1124,16 +1124,18 @@ int fapi_rx_ulsch_ind(fapi_t* fapi, fapi_rx_ulsch_ind_t* ind)
 	rx_ind.header.phy_id = data->p7_config->phy_id;
 	rx_ind.sfn_sf = ind->sfn_sf;
 	
-	if(((pnf_info*)(data->config->user_data))->wireshark_test_mode)
+	if(1)//((pnf_info*)(data->config->user_data))->wireshark_test_mode)
 	{
 		rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG;
-		rx_ind.rx_indication_body.number_of_pdus = 8;
+		rx_ind.rx_indication_body.number_of_pdus = 1;
 		
 		uint8_t rx_data[1024];
 		
 		nfapi_rx_indication_pdu_t pdus[rx_ind.rx_indication_body.number_of_pdus];
 		memset(&pdus, 0, sizeof(pdus));
 		
+                strcpy((char*)rx_data, (char*)"123456789");
+
 		for(int i = 0; i < rx_ind.rx_indication_body.number_of_pdus;++i)
 		{
 		
@@ -1142,13 +1144,13 @@ int fapi_rx_ulsch_ind(fapi_t* fapi, fapi_rx_ulsch_ind_t* ind)
 			pdus[i].rx_ue_information.rnti = rand_range(1, 65535);
 			
 			pdus[i].rx_indication_rel8.tl.tag = NFAPI_RX_INDICATION_REL8_TAG;
-			pdus[i].rx_indication_rel8.length = rand_range(0, 1024);
-			pdus[i].rx_indication_rel8.offset = 1;
+			pdus[i].rx_indication_rel8.length = 10;//rand_range(0, 1024);
+			pdus[i].rx_indication_rel8.offset = 0;//djp - 1;
 			pdus[i].rx_indication_rel8.ul_cqi = rand_range(0, 255);
 			pdus[i].rx_indication_rel8.timing_advance = rand_range(0, 63);
 			
-			pdus[i].rx_indication_rel9.tl.tag = NFAPI_RX_INDICATION_REL9_TAG;
-			pdus[i].rx_indication_rel9.timing_advance_r9 = rand_range(0, 7690);
+			//pdus[i].rx_indication_rel9.tl.tag = NFAPI_RX_INDICATION_REL9_TAG;
+			//pdus[i].rx_indication_rel9.timing_advance_r9 = rand_range(0, 7690);
 			
 			pdus[i].data = &rx_data[0];
 		}
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
diff --git a/vnf/inc/vnf_p7.h b/vnf/inc/vnf_p7.h
index ab9a335..fc2ab4e 100644
--- a/vnf/inc/vnf_p7.h
+++ b/vnf/inc/vnf_p7.h
@@ -116,7 +116,8 @@ typedef struct {
 	
 } vnf_p7_t;
 
-uint32_t get_current_time_hr();
+uint32_t vnf_get_current_time_hr(void);
+
 uint16_t increment_sfn_sf(uint16_t sfn_sf);
 int vnf_sync(vnf_p7_t* vnf_p7, nfapi_vnf_p7_connection_info_t* p7_info);
 int send_mac_subframe_indications(vnf_p7_t* config);
diff --git a/vnf/public_inc/nfapi_vnf_interface.h b/vnf/public_inc/nfapi_vnf_interface.h
index 6659e5d..4629013 100644
--- a/vnf/public_inc/nfapi_vnf_interface.h
+++ b/vnf/public_inc/nfapi_vnf_interface.h
@@ -450,7 +450,7 @@ typedef struct nfapi_vnf_config
 /*! Creates and initialise the vnf config structure before use
  * \return A pointer to a vnf config structure
  */
-nfapi_vnf_config_t* nfapi_vnf_config_create();
+nfapi_vnf_config_t* nfapi_vnf_config_create(void);
 
 /*! Delete an vnf config
  */
@@ -864,7 +864,7 @@ typedef struct nfapi_vnf_p7_config
 /*! Creates and initializes the nfapi_vnf_p7_config structure before use
  *  \return A pointer to an allocated vnf p7 configuration
  */
-nfapi_vnf_p7_config_t* nfapi_vnf_p7_config_create();
+nfapi_vnf_p7_config_t* nfapi_vnf_p7_config_create(void);
 
 /*! Cleanup and delete nfapi_vnf_p7_config structure
  *  \param config A pointer to an vnf p7 configuration structure
diff --git a/vnf/src/vnf.c b/vnf/src/vnf.c
index fea3cf7..6800ee2 100644
--- a/vnf/src/vnf.c
+++ b/vnf/src/vnf.c
@@ -82,11 +82,18 @@ void nfapi_vnf_pnf_list_add(nfapi_vnf_config_t* config, nfapi_vnf_pnf_info_t* no
 
 nfapi_vnf_pnf_info_t* nfapi_vnf_pnf_list_find(nfapi_vnf_config_t* config, int p5_idx)
 {
+	NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s : config->pnf_list:%p\n", __FUNCTION__, config->pnf_list);
+
 	nfapi_vnf_pnf_info_t* curr = config->pnf_list;
 	while(curr != 0)
 	{
 		if(curr->p5_idx == p5_idx)
+                {
+                  NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s : curr->p5_idx:%d p5_idx:%d\n", __FUNCTION__, curr->p5_idx, p5_idx);
 			return curr;
+                        }
+
+                NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s : curr->next:%p\n", __FUNCTION__, curr->next);
 
 		curr = curr->next;
 	}
diff --git a/vnf/src/vnf_interface.c b/vnf/src/vnf_interface.c
1042
index e559730..0aba0a2 100644
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
--- a/vnf/src/vnf_interface.c
+++ b/vnf/src/vnf_interface.c
@@ -342,6 +342,7 @@ int nfapi_vnf_start(nfapi_vnf_config_t* config)
 				{
 					NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF connection (fd:%d) accepted from %s:%d \n", p5Sock,  inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
 					nfapi_vnf_pnf_info_t* pnf = (nfapi_vnf_pnf_info_t*)malloc(sizeof(nfapi_vnf_pnf_info_t));
+					NFAPI_TRACE(NFAPI_TRACE_INFO, "MALLOC nfapi_vnf_pnf_info_t for pnf_list pnf:%p\n", pnf);
 					memset(pnf, 0, sizeof(nfapi_vnf_pnf_info_t));
 					pnf->p5_sock = p5Sock;
 					pnf->p5_idx = p5_idx++;
1053 1054 1055 1056 1057 1058 1059 1060 1061
@@ -663,7 +664,7 @@ int nfapi_vnf_allocate_phy(nfapi_vnf_config_t* config, int p5_idx, uint16_t* phy
 	info->p5_idx = p5_idx;
 	info->phy_id = vnf->next_phy_id++;
 
-	info->timing_window = 10;
+	info->timing_window = 30;       // This seems to override what gets set by the user - why???
 	info->timing_info_mode = 0x03;
 	info->timing_info_period = 128;
 
1062
diff --git a/vnf/src/vnf_p7.c b/vnf/src/vnf_p7.c
1063
index 8630385..70f97d6 100644
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
--- a/vnf/src/vnf_p7.c
+++ b/vnf/src/vnf_p7.c
@@ -15,6 +15,8 @@
  */
 
 
+#include <time.h>
+
 #include <sys/time.h>
 #include <stdlib.h>
 #include <string.h>
@@ -159,7 +161,7 @@ vnf_p7_rx_message_t* vnf_p7_rx_reassembly_queue_add_segment(vnf_p7_t* vnf_p7, vn
 		msg->sequence_number = sequence_number;
 		msg->num_segments_expected = m ? 255 : segment_number + 1;
 		msg->num_segments_received = 1;
-		msg->rx_hr_time = get_current_time_hr();
+		msg->rx_hr_time = vnf_get_current_time_hr();
 
 		msg->segments[segment_number].buffer = (uint8_t*)vnf_p7_malloc(vnf_p7, data_len);
 		memcpy(msg->segments[segment_number].buffer, data, data_len);
@@ -216,7 +218,7 @@ void vnf_p7_rx_reassembly_queue_remove_old_msgs(vnf_p7_t* vnf_p7, vnf_p7_rx_reas
 	vnf_p7_rx_message_t* iterator = queue->msg_queue;
 	vnf_p7_rx_message_t* previous = 0;
 
-	uint32_t rx_hr_time = get_current_time_hr();
+	uint32_t rx_hr_time = vnf_get_current_time_hr();
 
 	while(iterator != 0)
 	{
@@ -254,7 +256,7 @@ void vnf_p7_rx_reassembly_queue_remove_old_msgs(vnf_p7_t* vnf_p7, vnf_p7_rx_reas
 	}
 }
 
-uint32_t get_current_time_hr()
+uint32_t vnf_get_current_time_hr()
 {
 	struct timeval now;
 	(void)gettimeofday(&now, NULL);
@@ -297,7 +299,7 @@ struct timespec timespec_delta(struct timespec start, struct timespec end)
 	return temp;
 }
 
-uint32_t get_sf_time(uint32_t now_hr, uint32_t sf_start_hr)
+static uint32_t get_sf_time(uint32_t now_hr, uint32_t sf_start_hr)
 {
 	if(now_hr < sf_start_hr)
 	{
@@ -321,7 +323,7 @@ uint32_t get_sf_time(uint32_t now_hr, uint32_t sf_start_hr)
 
 uint32_t calculate_t1(uint16_t sfn_sf, uint32_t sf_start_time_hr)
 {
-	uint32_t now_time_hr = get_current_time_hr();
+	uint32_t now_time_hr = vnf_get_current_time_hr();
 
 	uint32_t sf_time_us = get_sf_time(now_time_hr, sf_start_time_hr);
 
@@ -344,7 +346,7 @@ uint32_t calculate_t4(uint32_t now_time_hr, uint16_t sfn_sf, uint32_t sf_start_t
 
 uint32_t calculate_transmit_timestamp(uint16_t sfn_sf, uint32_t sf_start_time_hr)
 {
-	uint32_t now_time_hr = get_current_time_hr();
+	uint32_t now_time_hr = vnf_get_current_time_hr();
 
 	uint32_t sf_time_us = get_sf_time(now_time_hr, sf_start_time_hr);
 
@@ -410,6 +412,8 @@ int vnf_p7_pack_and_send_p7_msg(vnf_p7_t* vnf_p7, nfapi_p7_message_header_t* hea
 		
 		int len = nfapi_p7_message_pack(header, buffer, sizeof(buffer), &vnf_p7->_public.codec_config);
 		
+                //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() phy_id:%d nfapi_p7_message_pack()=len=%d vnf_p7->_public.segment_size:%u\n", __FUNCTION__, header->phy_id, len, vnf_p7->_public.segment_size);
+
 		if(len < 0) 
 		{
 			NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() failed to pack p7 message phy_id:%d\n", __FUNCTION__, header->phy_id);
@@ -429,6 +433,7 @@ int vnf_p7_pack_and_send_p7_msg(vnf_p7_t* vnf_p7, nfapi_p7_message_header_t* hea
 			int segment = 0;
 			int offset = NFAPI_P7_HEADER_LENGTH;
 			uint8_t tx_buffer[vnf_p7->_public.segment_size];
+                        NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() MORE THAN ONE SEGMENT phy_id:%d nfapi_p7_message_pack()=len=%d vnf_p7->_public.segment_size:%u\n", __FUNCTION__, header->phy_id, len, vnf_p7->_public.segment_size);
 			for(segment = 0; segment < segment_count; ++segment)
 			{
 				uint8_t last = 0;
@@ -851,7 +856,7 @@ void vnf_handle_p7_vendor_extension(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vn
 
 void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 {
-	uint32_t now_time_hr = get_current_time_hr();
+	uint32_t now_time_hr = vnf_get_current_time_hr();
 
 	if (pRecvMsg == NULL || vnf_p7  == NULL)
 	{
@@ -871,7 +876,7 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 	nfapi_vnf_p7_connection_info_t* phy = vnf_p7_connection_info_list_find(vnf_p7, ind.header.phy_id);
 	uint32_t t4 = calculate_t4(now_time_hr, phy->sfn_sf, vnf_p7->sf_start_time_hr);
 
-	uint32_t tx_2_rx = t4 - ind.t1;
+	uint32_t tx_2_rx = t4>ind.t1 ? t4 - ind.t1 : t4 + NFAPI_MAX_SFNSFDEC - ind.t1 ;
 	uint32_t pnf_proc_time = ind.t3 - ind.t2;
 
 	// divide by 2 using shift operator
@@ -881,7 +886,7 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 	{
 		phy->latency[phy->min_sync_cycle_count] = latency;
 
-		NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%d/%d) PNF to VNF !sync phy_id:%d (t1/2/3/4:%8u, %8u, %8u, %8u) txrx:%4u procT:%3u latency(us):%4d\n",
+		NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%4d/%d) PNF to VNF !sync phy_id:%d (t1/2/3/4:%8u, %8u, %8u, %8u) txrx:%4u procT:%3u latency(us):%4d\n",
 				NFAPI_SFNSF2SFN(phy->sfn_sf), NFAPI_SFNSF2SF(phy->sfn_sf), ind.header.phy_id, ind.t1, ind.t2, ind.t3, t4, 
 				tx_2_rx, pnf_proc_time, latency);
 	}
@@ -923,15 +928,27 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 
 		if(1)
 		{
-			NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%4d/%1d) PNF to VNF phy_id:%2d (t1/2/3/4:%8u, %8u, %8u, %8u) txrx:%4u procT:%3u latency(us):%4d offset(us):%8d filtered(us):%8d wrap[t1:%u t2:%u]\n", 
-					NFAPI_SFNSF2SFN(phy->sfn_sf), NFAPI_SFNSF2SF(phy->sfn_sf), ind.header.phy_id,
+                  struct timespec ts;
+                  clock_gettime(CLOCK_MONOTONIC, &ts);
+
+			NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%4d/%1d) %d.%d PNF to VNF phy_id:%2d (t1/2/3/4:%8u, %8u, %8u, %8u) txrx:%4u procT:%3u latency(us):%4d(avg:%4d) offset(us):%8d filtered(us):%8d wrap[t1:%u t2:%u]\n", 
+					NFAPI_SFNSF2SFN(phy->sfn_sf), NFAPI_SFNSF2SF(phy->sfn_sf), ts.tv_sec, ts.tv_nsec, ind.header.phy_id,
 					ind.t1, ind.t2, ind.t3, t4, 
-					tx_2_rx, pnf_proc_time, latency, phy->sf_offset, phy->sf_offset_filtered,
+					tx_2_rx, pnf_proc_time, latency, phy->average_latency, phy->sf_offset, phy->sf_offset_filtered,
 					(ind.t1<phy->previous_t1), (ind.t2<phy->previous_t2));
 		}
 
 	}
 
+        if (phy->filtered_adjust && (phy->sf_offset_filtered > 1e6 || phy->sf_offset_filtered < -1e6))
+        {
+          phy->filtered_adjust = 0;
+          phy->zero_count=0;
+          phy->min_sync_cycle_count = 2;
+          phy->in_sync = 0;
+          NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s - ADJUST TOO BAD - go out of filtered phy->sf_offset_filtered:%d\n", __FUNCTION__, phy->sf_offset_filtered);
+        }
+
 	if(phy->min_sync_cycle_count)
 		phy->min_sync_cycle_count--;
 
@@ -954,7 +971,6 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 			phy->sf_offset = ind.t2 - (ind.t1 - phy->average_latency);
 
 			sfn_sf_dec += (phy->sf_offset / 1000);
-
 		}
 		else
 		{
1212 1213 1214 1215 1216 1217 1218
@@ -976,12 +992,11 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 		{
 			phy->adjustment = NFAPI_SFNSF2DEC(new_sfn_sf) - NFAPI_SFNSF2DEC(curr_sfn_sf);
 
-			//NFAPI_TRACE(NFAPI_TRACE_NOTE, "PNF to VNF phy_id:%d adjustment%d\n", ind.header.phy_id, phy->adjustment);
+			NFAPI_TRACE(NFAPI_TRACE_NOTE, "PNF to VNF phy_id:%d adjustment%d phy->previous_sf_offset_filtered:%d phy->previous_sf_offset_filtered:%d phy->sf_offset_trend:%d\n", ind.header.phy_id, phy->adjustment, phy->previous_sf_offset_filtered, phy->previous_sf_offset_filtered, phy->sf_offset_trend);
 
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
 			phy->previous_t1 = 0;
 			phy->previous_t2 = 0;
 
-
 			if(phy->previous_sf_offset_filtered > 0)
 			{
 				if( phy->sf_offset_filtered > phy->previous_sf_offset_filtered)
@@ -1083,9 +1098,14 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 
 						if(phy->insync_minor_adjustment != 0)
 						{
-							NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%d/%d) VNF phy_id:%d Apply minor insync adjustment %dus for %d suframes (sf_offset_filtered:%d) %d %d %d\n", 
+							NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%4d/%d) VNF phy_id:%d Apply minor insync adjustment %dus for %d subframes (sf_offset_filtered:%d) %d %d %d NEW:%d CURR:%d adjustment:%d\n", 
 										NFAPI_SFNSF2SFN(phy->sfn_sf), NFAPI_SFNSF2SF(phy->sfn_sf), ind.header.phy_id,
-										phy->insync_minor_adjustment, phy->insync_minor_adjustment_duration, phy->sf_offset_filtered, insync_minor_adjustment_1, insync_minor_adjustment_2, phy->sf_offset_trend); 
+										phy->insync_minor_adjustment, phy->insync_minor_adjustment_duration, 
+                                                                                phy->sf_offset_filtered, 
+                                                                                insync_minor_adjustment_1, insync_minor_adjustment_2, phy->sf_offset_trend,
+                                                                                NFAPI_SFNSF2DEC(new_sfn_sf),
+                                                                                NFAPI_SFNSF2DEC(curr_sfn_sf),
+                                                                                phy->adjustment); 
 						}
 					}
 				}
@@ -1121,10 +1141,13 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 								// out of sync?
 							}
 							
-							NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%d/%d) VNF phy_id:%d Apply minor insync adjustment %dus for %d suframes (adjusment:%d sf_offset_filtered:%d) %d %d %d\n", 
+							NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%4d/%d) VNF phy_id:%d Apply minor insync adjustment %dus for %d subframes (adjustment:%d sf_offset_filtered:%d) %d %d %d NEW:%d CURR:%d adj:%d\n", 
 										NFAPI_SFNSF2SFN(phy->sfn_sf), NFAPI_SFNSF2SF(phy->sfn_sf), ind.header.phy_id,
 										phy->insync_minor_adjustment, phy->insync_minor_adjustment_duration, phy->adjustment, phy->sf_offset_filtered,
-										insync_minor_adjustment_1, insync_minor_adjustment_2, phy->sf_offset_trend); 
+										insync_minor_adjustment_1, insync_minor_adjustment_2, phy->sf_offset_trend,
+                                                                                NFAPI_SFNSF2DEC(new_sfn_sf),
+                                                                                NFAPI_SFNSF2DEC(curr_sfn_sf),
+                                                                                phy->adjustment); 
 							
 						}
 						else if(phy->adjustment < 0)
@@ -1151,7 +1174,7 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 								// out of sync?
 							}
 
-							NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%d/%d) VNF phy_id:%d Apply minor insync adjustment %dus for %d suframes (adjusment:%d sf_offset_filtered:%d) %d %d %d\n", 
+							NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%d/%d) VNF phy_id:%d Apply minor insync adjustment %dus for %d subframes (adjustment:%d sf_offset_filtered:%d) %d %d %d\n", 
 										NFAPI_SFNSF2SFN(phy->sfn_sf), NFAPI_SFNSF2SF(phy->sfn_sf), ind.header.phy_id,
 										phy->insync_minor_adjustment, phy->insync_minor_adjustment_duration, phy->adjustment, phy->sf_offset_filtered,
 										insync_minor_adjustment_1, insync_minor_adjustment_2, phy->sf_offset_trend); 
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
@@ -1219,7 +1242,16 @@ void vnf_handle_timing_info(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 		return;
 	}
 
-	// todo : how to use this?
+        if (vnf_p7 && vnf_p7->p7_connections)
+        {
+          int16_t vnf_pnf_sfnsf_delta = NFAPI_SFNSF2DEC(vnf_p7->p7_connections[0].sfn_sf) - NFAPI_SFNSF2DEC(ind.last_sfn_sf);
+
+          //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() PNF:SFN/SF:%d VNF:SFN/SF:%d deltaSFNSF:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind.last_sfn_sf), NFAPI_SFNSF2DEC(vnf_p7->p7_connections[0].sfn_sf), vnf_pnf_sfnsf_delta);
+          if (vnf_pnf_sfnsf_delta>1 || vnf_pnf_sfnsf_delta < -1)
+          {
+            NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() LARGE SFN/SF DELTA between PNF and VNF\n\n\n\n\n\n\n\n\n", __FUNCTION__);
+          }
+        }
 }
 
 void vnf_dispatch_p7_message(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
1286
diff --git a/vnf/src/vnf_p7_interface.c b/vnf/src/vnf_p7_interface.c
1287
index ab4f00c..a35d8e3 100644
1288 1289 1290 1291 1292 1293
--- a/vnf/src/vnf_p7_interface.c
+++ b/vnf/src/vnf_p7_interface.c
@@ -142,6 +142,7 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "VNF P7 bind succeeded...\n");
 
 
1294
+	//struct timespec original_pselect_timeout;
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
 	struct timespec pselect_timeout;
 	pselect_timeout.tv_sec = 0;
 	pselect_timeout.tv_nsec = 1000000; // ns in a 1 us
@@ -157,13 +158,13 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 
 	struct timespec sf_duration;
 	sf_duration.tv_sec = 0;
-	sf_duration.tv_nsec = 1000000; // ns in a 1 us
+	sf_duration.tv_nsec = 1e6; // We want 1ms pause
 
 	struct timespec sf_start;
 	clock_gettime(CLOCK_MONOTONIC, &sf_start);
 	long millisecond = sf_start.tv_nsec / 1e6;
 	sf_start = timespec_add(sf_start, sf_duration);
-	//NFAPI_TRACE(NFAPI_TRACE_INFO, "next subframe will start at %d.%d\n", sf_start.tv_sec, sf_start.tv_nsec);
+	NFAPI_TRACE(NFAPI_TRACE_INFO, "next subframe will start at %d.%d\n", sf_start.tv_sec, sf_start.tv_nsec);
 
 	while(vnf_p7->terminate == 0)
 	{
@@ -181,6 +182,8 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 
 		if((last_millisecond == -1) || (millisecond == last_millisecond) || (millisecond == (last_millisecond + 1) % 1000) )
 		{
+                  //NFAPI_TRACE(NFAPI_TRACE_INFO, "pselect_start:%d.%d sf_start:%d.%d\n", pselect_start.tv_sec, pselect_start.tv_nsec, sf_start.tv_sec, sf_start.tv_nsec);
+
 
 			if((pselect_start.tv_sec > sf_start.tv_sec) || 
 			   ((pselect_start.tv_sec == sf_start.tv_sec) && (pselect_start.tv_nsec > sf_start.tv_nsec)))
1323
@@ -196,16 +199,26 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336
 			{
 				// still time before the end of the subframe wait
 				pselect_timeout = timespec_sub(sf_start, pselect_start);
+
+#if 0
+                                NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() sf_start:%d.%ld pselect_start:%d.%ld pseclect_timeout:%d.%ld\n",
+                                    __FUNCTION__,
+                                    sf_start.tv_sec, sf_start.tv_nsec,
+                                    pselect_start.tv_sec, pselect_start.tv_nsec,
+                                    pselect_timeout.tv_sec, pselect_timeout.tv_nsec);
+#endif
 			}
 
1337
+//original_pselect_timeout = pselect_timeout;
1338 1339 1340 1341
+
 			// detemine how long to sleep in ns before the start of the next 1ms
 			//pselect_timeout.tv_nsec = 1e6 - (pselect_start.tv_nsec % 1000000);
 
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
-			//uint8_t underun_possiable =0;
+			//uint8_t underrun_possible =0;
 			
 			// if we are not sleeping until the next milisecond due to the
 			// insycn minor adjment flag it so we don't consider it an error
-			//uint8_t underun_possiable =0;
+			//uint8_t underrun_possible =0;
 			/*
 			{
 				nfapi_vnf_p7_connection_info_t* phy = vnf_p7->p7_connections;
@@ -222,7 +235,7 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 							pselect_timeout.tv_nsec = pselect_timeout.tv_nsec - (phy->insync_minor_adjustment * 1000);
 
 
-						//underun_possiable = 1;
+						//underrun_possible = 1;
 					}
 					else if(phy->insync_minor_adjustment < 0)
 					{
@@ -237,41 +250,98 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
 			*/
 			
 
+//long wraps = pselect_timeout.tv_nsec % 1e9;
+
+
 			selectRetval = pselect(maxSock+1, &rfds, NULL, NULL, &pselect_timeout, NULL);
 
 			clock_gettime(CLOCK_MONOTONIC, &pselect_stop);
 
+                        nfapi_vnf_p7_connection_info_t* phy = vnf_p7->p7_connections;
+
+if (selectRetval==-1 && errno == 22)
+{
+  NFAPI_TRACE(NFAPI_TRACE_ERROR, "INVAL: pselect_timeout:%d.%ld adj[dur:%d adj:%d], sf_dur:%d.%ld\n", 
+  pselect_timeout.tv_sec, pselect_timeout.tv_nsec, 
+  phy->insync_minor_adjustment_duration, phy->insync_minor_adjustment, 
+  sf_duration.tv_sec, sf_duration.tv_nsec);
+}
+#if 0
+                        if (selectRetval != 0 || phy->insync_minor_adjustment_duration != 0)
+                          NFAPI_TRACE(NFAPI_TRACE_NOTE, "pselect()=%d maxSock:%d vnf_p7->socket:%d pselect_timeout:%u.%u original_pselect_timeout:%u.%u\n", 
+                              selectRetval, maxSock, vnf_p7->socket, pselect_timeout.tv_sec, pselect_timeout.tv_nsec,
+                              original_pselect_timeout.tv_sec, original_pselect_timeout.tv_nsec);
+#endif
+
 			if(selectRetval == 0)
 			{
-				// calcualte the start of the next subframe
+				// calculate the start of the next subframe
 				sf_start = timespec_add(sf_start, sf_duration);
 				//NFAPI_TRACE(NFAPI_TRACE_INFO, "next subframe will start at %d.%d\n", sf_start.tv_sec, sf_start.tv_nsec);
 
-				nfapi_vnf_p7_connection_info_t* phy = vnf_p7->p7_connections;
 				if(phy && phy->in_sync && phy->insync_minor_adjustment != 0 && phy->insync_minor_adjustment_duration > 0)
 				{
-					NFAPI_TRACE(NFAPI_TRACE_NOTE, "[VNF] Subframe minor adjustment %dus\n", phy->insync_minor_adjustment);
+                                        long insync_minor_adjustment_ns = (phy->insync_minor_adjustment * 1000);
+
+                                        sf_start.tv_nsec -= insync_minor_adjustment_ns;
+
+#if 1
+                                        if (sf_start.tv_nsec > 1e9)
+                                        {
+                                          sf_start.tv_sec++;
+                                          sf_start.tv_nsec-=1e9;
+                                        }
+                                        else if (sf_start.tv_nsec < 0)
+                                        {
+                                          sf_start.tv_sec--;
+                                          sf_start.tv_nsec+=1e9;
+                                        }
+#else
+                                        //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[VNF] BEFORE adjustment - Subframe minor adjustment %dus sf_start.tv_nsec:%d\n", phy->insync_minor_adjustment, sf_start.tv_nsec);
 					if(phy->insync_minor_adjustment > 0)
 					{
 						// decrease the subframe duration a little
-						sf_start.tv_nsec = sf_start.tv_nsec - (phy->insync_minor_adjustment * 1000);
+                                                if (sf_start.tv_nsec > insync_minor_adjustment_ns)
+                                                  sf_start.tv_nsec -= insync_minor_adjustment_ns;
+                                                else
+                                                {
+                                                  NFAPI_TRACE(NFAPI_TRACE_ERROR, "[VNF] Adjustment would make it negative sf:%d.%ld adjust:%ld\n\n\n", sf_start.tv_sec, sf_start.tv_nsec, insync_minor_adjustment_ns);
+                                                  sf_start.tv_sec--;
+                                                  sf_start.tv_nsec += 1e9 - insync_minor_adjustment_ns;
+                                                }
 					}
 					else if(phy->insync_minor_adjustment < 0)
 					{
 						// todo check we don't go below 0
 						// increase the subframe duration a little
-						sf_start.tv_nsec = sf_start.tv_nsec - (phy->insync_minor_adjustment * 1000);
+						sf_start.tv_nsec += insync_minor_adjustment_ns;
+
+                                                if (sf_start.tv_nsec < 0)
+                                                {
+                                                  NFAPI_TRACE(NFAPI_TRACE_ERROR, "[VNF] OVERFLOW %d.%ld\n\n\n\n", sf_start.tv_sec, sf_start.tv_nsec);
+                                                  sf_start.tv_sec++;
+                                                  sf_start.tv_nsec += 1e9;
+                                                }
 					}
+#endif
 
 					//phy->insync_minor_adjustment = 0;
-					phy->insync_minor_adjustment_duration--;
+                                        phy->insync_minor_adjustment_duration--;
+
+                                        NFAPI_TRACE(NFAPI_TRACE_NOTE, "[VNF] AFTER adjustment - Subframe minor adjustment %dus sf_start.tv_nsec:%d duration:%u\n", 
+                                            phy->insync_minor_adjustment, sf_start.tv_nsec, phy->insync_minor_adjustment_duration);
+
+                                        if (phy->insync_minor_adjustment_duration==0)
+                                        {
+                                          phy->insync_minor_adjustment = 0;
+                                        }
 				}
 				/*
 				long pselect_stop_millisecond = pselect_stop.tv_nsec / 1e6;
1459 1460 1461 1462 1463 1464 1465 1466
 				if(millisecond == pselect_stop_millisecond)
 				{
 					// we have woke up in the same subframe
-					if(underun_possiable == 0)
+					if(underrun_possible == 0)
 						NFAPI_TRACE(NFAPI_TRACE_WARN, "subframe pselect underrun %ld (%d.%d)\n", millisecond, pselect_stop.tv_sec, pselect_stop.tv_nsec);
 				}
 				else if(((millisecond + 1) % 1000) != pselect_stop_millisecond)
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520
@@ -298,7 +368,7 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 
 		if(selectRetval == 0)
 		{
-			vnf_p7->sf_start_time_hr = get_current_time_hr();
+			vnf_p7->sf_start_time_hr = vnf_get_current_time_hr();
 
 			// pselect timed out
 			nfapi_vnf_p7_connection_info_t* curr = vnf_p7->p7_connections;
@@ -326,14 +396,18 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 		else
 		{
 			// pselect error
-			if(selectRetval == EINTR)
+			if(selectRetval == -1 && errno == EINTR)
 			{
 				// a sigal was received.
 			}
 			else
 			{
-				NFAPI_TRACE(NFAPI_TRACE_INFO, "P7 select failed result %d errno %d timeout:%d.%d\n", selectRetval, errno, pselect_timeout.tv_sec, pselect_timeout.tv_nsec);
+				NFAPI_TRACE(NFAPI_TRACE_INFO, "P7 select failed result %d errno %d timeout:%d.%d orginal:%d.%d last_ms:%ld ms:%ld\n", selectRetval, errno, pselect_timeout.tv_sec, pselect_timeout.tv_nsec, pselect_timeout.tv_sec, pselect_timeout.tv_nsec, last_millisecond, millisecond);
 				// should we exit now?
+                                if (selectRetval == -1 && errno == 22) // invalid argument??? not sure about timeout duration
+                                {
+                                  usleep(100000);
+                                }
 			}
 		}
 
@@ -360,10 +434,12 @@ int nfapi_vnf_p7_stop(nfapi_vnf_p7_config_t* config)
 
 int nfapi_vnf_p7_add_pnf(nfapi_vnf_p7_config_t* config, const char* pnf_p7_addr, int pnf_p7_port, int phy_id)
 {
-	NFAPI_TRACE(NFAPI_TRACE_INFO, "%s(phy_id:%d pnf_addr:%s:%d)\n", __FUNCTION__, phy_id,  pnf_p7_addr, pnf_p7_port);
+	NFAPI_TRACE(NFAPI_TRACE_INFO, "%s(config:%p phy_id:%d pnf_addr:%s pnf_p7_port:%d)\n", __FUNCTION__, config, phy_id,  pnf_p7_addr, pnf_p7_port);
 
 	if(config == 0)
-		return -1;
+        {
+          return -1;
+        }
 
 	vnf_p7_t* vnf_p7 = (vnf_p7_t*)config;
 
@@ -411,6 +487,8 @@ int nfapi_vnf_p7_del_pnf(nfapi_vnf_p7_config_t* config, int phy_id)
 }
 int nfapi_vnf_p7_dl_config_req(nfapi_vnf_p7_config_t* config, nfapi_dl_config_request_t* req)
 {
+	//NFAPI_TRACE(NFAPI_TRACE_INFO, "%s(config:%p req:%p)\n", __FUNCTION__, config, req);
+
 	if(config == 0 || req == 0)
 		return -1;
 
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
diff --git a/vnf_sim/src/mac.cpp b/vnf_sim/src/mac.cpp
index aa97f72..fa6f487 100644
--- a/vnf_sim/src/mac.cpp
+++ b/vnf_sim/src/mac.cpp
@@ -743,7 +743,7 @@ extern "C"
 			{
 				cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.number_of_cc = 1;
 				cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = rand_range(0, 3);
-				cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size = rand_range(0, 255);
+				cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[0] = rand_range(0, 255);
 			}
 			
 			cqi_ri_information.cqi_ri_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL13_TAG;
diff --git a/vnf_sim/src/main.cpp b/vnf_sim/src/main.cpp
index b79ac40..5dc7161 100644
--- a/vnf_sim/src/main.cpp
+++ b/vnf_sim/src/main.cpp
@@ -428,6 +428,20 @@ void phy_deallocate_p7_vendor_ext(nfapi_p7_message_header_t* header)
 	free(header);
 }
 
+//static pthread_t vnf_start_pthread;
+static pthread_t vnf_p7_start_pthread;
+void* vnf_p7_start_thread(void *ptr)
+{
+  printf("%s()\n", __FUNCTION__);
+
+  //std::shared_ptr<nfapi_vnf_p7_config> config = std::shared_ptr<nfapi_vnf_p7_config>(ptr);
+  nfapi_vnf_p7_config_t *config = (nfapi_vnf_p7_config_t *)ptr;
+
+  nfapi_vnf_p7_start(config);
+
+  return 0;
+}
+
 void set_thread_priority(int priority)
 {
 	//printf("%s(priority:%d)\n", __FUNCTION__, priority);
@@ -458,6 +472,8 @@ void set_thread_priority(int priority)
 
 void* vnf_p7_thread_start(void* ptr)
 {
+  printf("%s()\n", __FUNCTION__);
+
 	set_thread_priority(79);
 
 	vnf_p7_info* p7_vnf = (vnf_p7_info*)ptr;
@@ -494,10 +510,10 @@ void* vnf_p7_thread_start(void* ptr)
 	p7_vnf->config->allocate_p7_vendor_ext = &phy_allocate_p7_vendor_ext;
 	p7_vnf->config->deallocate_p7_vendor_ext = &phy_deallocate_p7_vendor_ext;
 
-	nfapi_vnf_p7_start(p7_vnf->config.get());
+        printf("[VNF] Creating VNF NFAPI start thread %s\n", __FUNCTION__);
+        pthread_create(&vnf_p7_start_pthread, NULL, &vnf_p7_start_thread, p7_vnf->config.get());
 
 	return 0;
-
 }
 
 int pnf_connection_indication_cb(nfapi_vnf_config_t* config, int p5_idx)
1581
diff --git a/xml/pnf_phy_1_A.xml b/xml/pnf_phy_1_A.xml
1582
index da6cc26..45f8f46 100644
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594
--- a/xml/pnf_phy_1_A.xml
+++ b/xml/pnf_phy_1_A.xml
@@ -26,7 +26,7 @@
 		<phy>
 			<index>88</index>
 			<port>2500</port>
-			<address>127.0.0.1</address>
+			<address>192.168.1.74</address>
 
 			<duplex_mode>1</duplex_mode>
 
@@ -54,9 +54,9 @@
Raymond Knopp's avatar
Raymond Knopp committed
1595
 
1596 1597 1598 1599 1600 1601
 			<data>
 				<udp>
-					<rx_port>7722</rx_port>
-					<tx_addr>127.0.0.1</tx_addr>
-					<tx_port>7733</tx_port>
+					<rx_port>5201</rx_port>
1602
+					<tx_addr>192.168.1.28</tx_addr>
1603 1604 1605 1606 1607
+					<tx_port>5200</tx_port>
 				</udp>
 			</data>
 		</phy>
diff --git a/xml/vnf_A.xml b/xml/vnf_A.xml
1608
index e609c93..3791239 100644
1609 1610 1611 1612 1613 1614 1615 1616 1617
--- a/xml/vnf_A.xml
+++ b/xml/vnf_A.xml
@@ -2,8 +2,8 @@
 <vnf>
 	<vnf_p7_list>
 		<vnf_p7>
-			<port>5200</port>
-			<address>127.0.0.1</address>
+			<port>5201</port>
1618
+			<address>192.168.1.28</address>
1619 1620 1621 1622 1623 1624 1625 1626
 			<timing_window>10</timing_window>
 			<periodic_timing_enabled>0</periodic_timing_enabled>
 			<periodic_timing_window>0</periodic_timing_window>
@@ -12,7 +12,7 @@
 			<data>
 				<udp>
 					<rx_port>8891</rx_port>
-					<tx_addr>127.0.0.1</tx_addr>
1627
+					<tx_addr>192.168.1.28</tx_addr>
1628 1629 1630
 					<tx_port>8892</tx_port>
 				</udp>
 			</data>