ptp working
This commit is contained in:
parent
e9e15caea8
commit
0500dc1c21
@ -134,7 +134,7 @@ locore_main(void * _unused __rte_unused)
|
||||
pkt_data = construct_udp_pkt_hdr(tx_buf,
|
||||
&options.s_host_mac, &options.server_mac,
|
||||
RTE_IPV4(192, 168, 100, 150), RTE_IPV4(192, 168, 100, 151),
|
||||
1337, 1337);
|
||||
333, 319);
|
||||
if (pkt_data == NULL) {
|
||||
rte_exit(EXIT_FAILURE, "cannot allocate space for packet_data in mbuf\n");
|
||||
}
|
||||
@ -264,6 +264,10 @@ port_init(uint16_t portid, struct rte_mempool *mbuf_pool)
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
ret = rte_eth_timesync_enable(portid);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
/* Enable RX in promiscuous mode for the Ethernet device. */
|
||||
ret = rte_eth_promiscuous_enable(portid);
|
||||
if (ret != 0)
|
||||
@ -404,6 +408,9 @@ int main(int argc, char* argv[])
|
||||
dump_options();
|
||||
|
||||
uint16_t core_id = rte_get_next_lcore(0, true, false);
|
||||
|
||||
sleep(1);
|
||||
|
||||
if (rte_eal_remote_launch(locore_main, NULL, core_id) != 0) {
|
||||
rte_exit(EXIT_FAILURE, "failed to launch function on locore\n");
|
||||
}
|
||||
|
15
inc/pkt.h
15
inc/pkt.h
@ -24,6 +24,8 @@ struct packet_hdr {
|
||||
struct rte_ether_hdr eth_hdr;
|
||||
struct rte_ipv4_hdr ipv4_hdr;
|
||||
struct rte_udp_hdr udp_hdr;
|
||||
uint8_t ptp_msg_type;
|
||||
uint8_t ptp_ver;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct packet_data
|
||||
@ -115,7 +117,7 @@ struct packet_data * construct_udp_pkt_hdr(struct rte_mbuf * buf,
|
||||
struct rte_ipv4_hdr * ipv4_hdr;
|
||||
struct rte_udp_hdr * udp_hdr;
|
||||
|
||||
if (pkt_data == NULL)
|
||||
if (pkt_data == NULL)
|
||||
return NULL;
|
||||
|
||||
// single segment
|
||||
@ -153,6 +155,17 @@ struct packet_data * construct_udp_pkt_hdr(struct rte_mbuf * buf,
|
||||
sizeof(struct rte_udp_hdr));
|
||||
buf->l4_len = sizeof(struct rte_udp_hdr);
|
||||
|
||||
// construct ptp header
|
||||
// so basically after some experiments at least the intel NIC categorizes PTP packets as:
|
||||
// 1. Dest port 319 2. these two fields must be set and don't care about others
|
||||
// Experiments:
|
||||
// SPORT: 319 DPORT: 319 PTP HDR: valid => SET
|
||||
// SPORT: 333 DPORT: 319 PTP HDR: valid => SET
|
||||
// SPORT: 319 DPORT: 333 PTP HDR: valid => NOT SET
|
||||
// SPORT: 319 DPORT: 319 PTP HDR: invalid => NOT SET
|
||||
pkt_data->pkt_hdr.ptp_ver = 0x2; // VER 2
|
||||
pkt_data->pkt_hdr.ptp_msg_type = 0x0; // SYNC
|
||||
|
||||
return pkt_data;
|
||||
}
|
||||
|
||||
|
32
khat/khat.cc
32
khat/khat.cc
@ -1,16 +1,19 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <netinet/in.h>
|
||||
#include <rte_config.h>
|
||||
#include <rte_common.h>
|
||||
#include <rte_eal.h>
|
||||
#include <rte_ethdev.h>
|
||||
#include <rte_cycles.h>
|
||||
#include <rte_lcore.h>
|
||||
#include <rte_mbuf.h>
|
||||
#include <rte_byteorder.h>
|
||||
#include <rte_config.h>
|
||||
#include <rte_ether.h>
|
||||
#include <rte_launch.h>
|
||||
#include <rte_log.h>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pkt.h"
|
||||
@ -117,7 +120,7 @@ locore_main(void * _unused __rte_unused)
|
||||
rte_pktmbuf_free(bufs[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
uint32_t dst_ip = rte_be_to_cpu_32(pkt_data->pkt_hdr.ipv4_hdr.dst_addr);
|
||||
uint32_t src_ip = rte_be_to_cpu_32(pkt_data->pkt_hdr.ipv4_hdr.src_addr);
|
||||
uint16_t src_port = rte_be_to_cpu_16(pkt_data->pkt_hdr.udp_hdr.src_port);
|
||||
@ -148,6 +151,19 @@ locore_main(void * _unused __rte_unused)
|
||||
src_port,
|
||||
dst_port,
|
||||
rte_be_to_cpu_32(pkt_data->epoch));
|
||||
//if (bufs[i]->ol_flags & PKT_RX_IEEE1588_TMST) {
|
||||
struct timespec ts;
|
||||
if (rte_eth_timesync_read_rx_timestamp(options.s_portid, &ts, bufs[i]->timesync & 0x3) == 0) {
|
||||
|
||||
ntr(NTR_DEP_USER1, NTR_LEVEL_DEBUG, "Timestamped sec: %lld nsec: %lld\n", ts.tv_sec, ts.tv_nsec);
|
||||
} else {
|
||||
ntr(NTR_DEP_USER1, NTR_LEVEL_DEBUG, "Not Timestamped!\n");
|
||||
}
|
||||
// }
|
||||
// else {
|
||||
// ntr(NTR_DEP_USER1, NTR_LEVEL_DEBUG, "Not Timestamped!\n");
|
||||
// }
|
||||
|
||||
// swap s_addr and d_addr
|
||||
struct rte_mbuf * pkt_buf = rte_pktmbuf_alloc(options.s_pkt_mempool);
|
||||
if (pkt_buf == NULL) {
|
||||
@ -250,7 +266,11 @@ port_init(uint16_t portid, struct rte_mempool *mbuf_pool)
|
||||
ret = rte_eth_macaddr_get(portid, &addr);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
|
||||
ret = rte_eth_timesync_enable(portid);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
/* Enable RX in promiscuous mode for the Ethernet device. */
|
||||
ret = rte_eth_promiscuous_enable(portid);
|
||||
if (ret != 0)
|
||||
@ -356,6 +376,8 @@ int main(int argc, char* argv[])
|
||||
if (lcore_id == RTE_MAX_LCORE) {
|
||||
rte_exit(EXIT_FAILURE, "cannot detect lcores.\n");
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
if (rte_eal_remote_launch(locore_main, NULL, lcore_id) != 0) {
|
||||
rte_exit(EXIT_FAILURE, "failed to launch function on locore %d\n", lcore_id);
|
||||
|
Loading…
Reference in New Issue
Block a user