本文整理汇总了C++中rte_memcpy函数的典型用法代码示例。如果您正苦于以下问题:C++ rte_memcpy函数的具体用法?C++ rte_memcpy怎么用?C++ rte_memcpy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rte_memcpy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: classify_pattern_skip_void_item
/* Skip all VOID items of the pattern */
void
classify_pattern_skip_void_item(struct rte_flow_item *items,
const struct rte_flow_item *pattern)
{
uint32_t cpy_count = 0;
const struct rte_flow_item *pb = pattern, *pe = pattern;
for (;;) {
/* Find a non-void item first */
pb = classify_find_first_item(pb, false);
if (pb->type == RTE_FLOW_ITEM_TYPE_END) {
pe = pb;
break;
}
/* Find a void item */
pe = classify_find_first_item(pb + 1, true);
cpy_count = pe - pb;
rte_memcpy(items, pb, sizeof(struct rte_flow_item) * cpy_count);
items += cpy_count;
if (pe->type == RTE_FLOW_ITEM_TYPE_END) {
pb = pe;
break;
}
pb = pe + 1;
}
/* Copy the END item. */
rte_memcpy(items, pe, sizeof(struct rte_flow_item));
}
示例2: copy_buf_to_pkt_segs
static void
copy_buf_to_pkt_segs(void* buf, unsigned len, struct rte_mbuf *pkt,
unsigned offset)
{
struct rte_mbuf *seg;
void *seg_buf;
unsigned copy_len;
seg = pkt;
while (offset >= seg->data_len) {
offset -= seg->data_len;
seg = seg->next;
}
copy_len = seg->data_len - offset;
seg_buf = rte_pktmbuf_mtod_offset(seg, char *, offset);
while (len > copy_len) {
rte_memcpy(seg_buf, buf, (size_t) copy_len);
len -= copy_len;
buf = ((char*) buf + copy_len);
seg = seg->next;
seg_buf = rte_pktmbuf_mtod(seg, char *);
copy_len = seg->data_len;
}
rte_memcpy(seg_buf, buf, (size_t) len);
}
示例3: addr_sa_to_xaddr
int addr_sa_to_xaddr(struct sockaddr* sa, socklen_t slen, struct xaddr* xa) {
struct sockaddr_in* in4 = (struct sockaddr_in*)sa;
struct sockaddr_in6* in6 = (struct sockaddr_in6*)sa;
memset(xa, '\0', sizeof(*xa));
switch (sa->sa_family) {
case AF_INET:
if (slen < sizeof(*in4))
return (-1);
xa->af = AF_INET;
rte_memcpy(&xa->v4, &in4->sin_addr, sizeof(xa->v4));
break;
case AF_INET6:
if (slen < sizeof(*in6))
return (-1);
xa->af = AF_INET6;
rte_memcpy(&xa->v6, &in6->sin6_addr, sizeof(xa->v6));
xa->scope_id = in6->sin6_scope_id;
break;
default:
return (-1);
}
return (0);
}
示例4: file_read_cached
static int file_read_cached(const char *file_name, uint8_t **mem, uint32_t beg, uint32_t len, uint32_t socket, struct hash_set *hs)
{
if (len == 0) {
*mem = 0;
return 0;
}
uint8_t *data_mem;
/* Since the configuration can reference the same file from
multiple places, use prox_shared infrastructure to detect
this and return previously loaded data. */
char name[256];
snprintf(name, sizeof(name), "%u-%u:%s", beg, len, file_name);
*mem = prox_sh_find_socket(socket, name);
if (*mem)
return 0;
/* check if the file has been loaded on the other socket. */
if (socket == 1 && (data_mem = prox_sh_find_socket(0, name))) {
uint8_t *data_find = hash_set_find(hs, data_mem, len);
if (!data_find) {
data_find = prox_zmalloc(len, socket);
PROX_PANIC(data_find == NULL, "Failed to allocate memory (%u bytes) to hold header for peer\n", len);
rte_memcpy(data_find, data_mem, len);
hash_set_add(hs, data_find, len);
}
*mem = data_find;
prox_sh_add_socket(socket, name, *mem);
return 0;
}
/* It is possible that a file with a different name contains
the same data. In that case, search all loaded files and
compare the data to reduce memory utilization.*/
data_mem = malloc(len);
PROX_PANIC(data_mem == NULL, "Failed to allocate temporary memory to hold data\n");
if (file_read_content(file_name, data_mem, beg, len)) {
plog_err("%s\n", file_get_error());
return -1;
}
uint8_t *data_find = hash_set_find(hs, data_mem, len);
if (!data_find) {
data_find = prox_zmalloc(len, socket);
PROX_PANIC(data_find == NULL, "Failed to allocate memory (%u bytes) to hold header for peer\n", len);
rte_memcpy(data_find, data_mem, len);
hash_set_add(hs, data_find, len);
}
free(data_mem);
*mem = data_find;
prox_sh_add_socket(socket, name, *mem);
return 0;
}
示例5: dpdk_link_send_bulk
/* Sends 'num_pkts' 'packets' and 'request' data to datapath. */
int
dpdk_link_send_bulk(struct dpif_dpdk_message *request,
const struct ofpbuf *const *packets, size_t num_pkts)
{
struct rte_mbuf *mbufs[PKT_BURST_SIZE] = {NULL};
uint8_t *mbuf_data = NULL;
int i = 0;
int ret = 0;
if (num_pkts > PKT_BURST_SIZE) {
return EINVAL;
}
DPDK_DEBUG()
for (i = 0; i < num_pkts; i++) {
mbufs[i] = rte_pktmbuf_alloc(mp);
if (!mbufs[i]) {
return ENOBUFS;
}
mbuf_data = rte_pktmbuf_mtod(mbufs[i], uint8_t *);
rte_memcpy(mbuf_data, &request[i], sizeof(request[i]));
if (request->type == DPIF_DPDK_PACKET_FAMILY) {
mbuf_data = mbuf_data + sizeof(request[i]);
if (likely(packets[i]->size <= (mbufs[i]->buf_len - sizeof(request[i])))) {
rte_memcpy(mbuf_data, packets[i]->data, packets[i]->size);
rte_pktmbuf_data_len(mbufs[i]) =
sizeof(request[i]) + packets[i]->size;
rte_pktmbuf_pkt_len(mbufs[i]) = rte_pktmbuf_data_len(mbufs[i]);
} else {
RTE_LOG(ERR, APP, "%s, %d: %s", __FUNCTION__, __LINE__,
"memcpy prevented: packet size exceeds available mbuf space");
for (i = 0; i < num_pkts; i++) {
rte_pktmbuf_free(mbufs[i]);
}
return ENOMEM;
}
} else {
rte_pktmbuf_data_len(mbufs[i]) = sizeof(request[i]);
rte_pktmbuf_pkt_len(mbufs[i]) = rte_pktmbuf_data_len(mbufs[i]);
}
}
ret = rte_ring_sp_enqueue_bulk(message_ring, (void * const *)mbufs, num_pkts);
if (ret == -ENOBUFS) {
for (i = 0; i < num_pkts; i++) {
rte_pktmbuf_free(mbufs[i]);
}
ret = ENOBUFS;
} else if (unlikely(ret == -EDQUOT)) {
ret = EDQUOT;
}
return ret;
}
示例6: lio_mbox_process_message
/**
* Process the received mbox message.
*/
int
lio_mbox_process_message(struct lio_mbox *mbox)
{
struct lio_mbox_cmd mbox_cmd;
if (mbox->state & LIO_MBOX_STATE_ERROR) {
if (mbox->state & (LIO_MBOX_STATE_RES_PENDING |
LIO_MBOX_STATE_RES_RECEIVING)) {
rte_memcpy(&mbox_cmd, &mbox->mbox_resp,
sizeof(struct lio_mbox_cmd));
mbox->state = LIO_MBOX_STATE_IDLE;
rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg);
mbox_cmd.recv_status = 1;
if (mbox_cmd.fn)
mbox_cmd.fn(mbox->lio_dev, &mbox_cmd,
mbox_cmd.fn_arg);
return 0;
}
mbox->state = LIO_MBOX_STATE_IDLE;
rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg);
return 0;
}
if (mbox->state & LIO_MBOX_STATE_RES_RECEIVED) {
rte_memcpy(&mbox_cmd, &mbox->mbox_resp,
sizeof(struct lio_mbox_cmd));
mbox->state = LIO_MBOX_STATE_IDLE;
rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg);
mbox_cmd.recv_status = 0;
if (mbox_cmd.fn)
mbox_cmd.fn(mbox->lio_dev, &mbox_cmd, mbox_cmd.fn_arg);
return 0;
}
if (mbox->state & LIO_MBOX_STATE_REQ_RECEIVED) {
rte_memcpy(&mbox_cmd, &mbox->mbox_req,
sizeof(struct lio_mbox_cmd));
if (!mbox_cmd.msg.s.resp_needed) {
mbox->state &= ~LIO_MBOX_STATE_REQ_RECEIVED;
if (!(mbox->state & LIO_MBOX_STATE_RES_PENDING))
mbox->state = LIO_MBOX_STATE_IDLE;
rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg);
}
lio_mbox_process_cmd(mbox, &mbox_cmd);
return 0;
}
RTE_ASSERT(0);
return 0;
}
示例7: pktgen_send_arp
void
pktgen_send_arp( uint32_t pid, uint32_t type, uint8_t seq_idx )
{
port_info_t * info = &pktgen.info[pid];
pkt_seq_t * pkt;
struct rte_mbuf * m ;
struct ether_hdr * eth;
arpPkt_t * arp;
uint32_t addr;
uint8_t qid = 0;
pkt = &info->seq_pkt[seq_idx];
m = rte_pktmbuf_alloc(info->q[qid].special_mp);
if ( unlikely(m == NULL) ) {
pktgen_log_warning("No packet buffers found");
return;
}
eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
arp = (arpPkt_t *)ð[1];
/* src and dest addr */
memset(ð->d_addr, 0xFF, 6);
ether_addr_copy(&pkt->eth_src_addr, ð->s_addr);
eth->ether_type = htons(ETHER_TYPE_ARP);
memset(arp, 0, sizeof(arpPkt_t));
rte_memcpy( &arp->sha, &pkt->eth_src_addr, 6 );
addr = htonl(pkt->ip_src_addr);
inetAddrCopy(&arp->spa, &addr);
if ( likely(type == GRATUITOUS_ARP) ) {
rte_memcpy( &arp->tha, &pkt->eth_src_addr, 6 );
addr = htonl(pkt->ip_src_addr);
inetAddrCopy(&arp->tpa, &addr);
} else {
memset( &arp->tha, 0, 6 );
addr = htonl(pkt->ip_dst_addr);
inetAddrCopy(&arp->tpa, &addr);
}
/* Fill in the rest of the ARP packet header */
arp->hrd = htons(ETH_HW_TYPE);
arp->pro = htons(ETHER_TYPE_IPv4);
arp->hln = 6;
arp->pln = 4;
arp->op = htons(ARP_REQUEST);
m->pkt.pkt_len = 60;
m->pkt.data_len = 60;
pktgen_send_mbuf(m, pid, qid);
pktgen_set_q_flags(info, qid, DO_TX_FLUSH);
}
示例8: qCritical
/**
* @brief Copy a buffer to mbuf
*
* @param devId port number
* @param data Data buffer
* @param dataLen Data buffer length
* @param pMbuf mbuf
*
* @return true on success
*/
bool DPDKAdapter::copyBufToMbuf(uint8_t devId, char* data, unsigned int dataLen, MBuf_t*& pMbuf)
{
unsigned int offset = 0;
pMbuf = NULL;
pMbuf = DPDKAdapter::instance()->txMbufAlloc(devId);
if (pMbuf == NULL)
{
qCritical("No mbuf available");
return false;
}
pMbuf->pkt.data_len = dataLen < MAX_SEG_SIZE ? dataLen : MAX_SEG_SIZE;
pMbuf->pkt.pkt_len = dataLen;
pMbuf->pkt.nb_segs = (dataLen / MAX_SEG_SIZE) + ((dataLen % MAX_SEG_SIZE) || 0);
qDebug("pkt_len %u, data_len %u, nb_segs %u",pMbuf->pkt.pkt_len, pMbuf->pkt.data_len, pMbuf->pkt.nb_segs);
rte_memcpy(pMbuf->pkt.data, data, pMbuf->pkt.data_len);
if (dataLen <= MAX_SEG_SIZE)
{
return true;
}
dataLen -= pMbuf->pkt.data_len;
offset = pMbuf->pkt.data_len;
MBuf_t* pCurMbuf = pMbuf;
while (dataLen > 0)
{
qDebug("offset %u, dataLen %u", offset, dataLen);
pCurMbuf->pkt.next = DPDKAdapter::instance()->txMbufAlloc(devId);
if (pCurMbuf->pkt.next == NULL)
{
qCritical("No mbuf available");
return false;
}
pCurMbuf = pCurMbuf->pkt.next;
pCurMbuf->pkt.data_len = dataLen < MAX_SEG_SIZE ? dataLen : MAX_SEG_SIZE;
qDebug("pkt_len %u, data_len %u, nb_segs %u",pCurMbuf->pkt.pkt_len, pCurMbuf->pkt.data_len, pCurMbuf->pkt.nb_segs);
rte_memcpy(pCurMbuf->pkt.data, data + offset, pCurMbuf->pkt.data_len);
dataLen -= pCurMbuf->pkt.data_len;
offset += pCurMbuf->pkt.data_len;
}
return true;
}
示例9: trace_entry_dump
/*****************************************************************************
* trace_entry_dump()
****************************************************************************/
void trace_entry_dump(trace_printer_cb_t printer, void *printer_arg,
trace_printer_fmt_cb_t fmt, const char *comp_name,
const char *buffer, uint32_t bufsize, uint32_t *start_id,
uint32_t *start_pos, uint32_t end_pos)
{
uint32_t old_start = *start_pos;
uint32_t start_raw;
trace_level_t te_lvl;
uint32_t te_len;
uint32_t len_to_copy;
trace_entry_hdr_peek_buf(buffer, bufsize, old_start, start_id,
&te_lvl, &te_len);
len_to_copy = te_len - offsetof(trace_entry_t, te_buf);
start_raw = (old_start + offsetof(trace_entry_t, te_buf)) % bufsize;
if (start_raw + len_to_copy > bufsize) {
/* LOCAL copy! */
char raw_entry[len_to_copy];
rte_memcpy(raw_entry, &buffer[start_raw], bufsize - start_raw);
rte_memcpy(&raw_entry[bufsize - start_raw], buffer,
len_to_copy - (bufsize - start_raw));
if (fmt) {
char *fmt_data = fmt(raw_entry, te_len);
printer(printer_arg, te_lvl, comp_name, fmt_data,
strlen(fmt_data));
} else
printer(printer_arg, te_lvl, comp_name, raw_entry, te_len);
*start_pos = len_to_copy - (bufsize - start_raw);
} else {
if (fmt) {
char *fmt_data = fmt(&buffer[start_raw], te_len);
printer(printer_arg, te_lvl, comp_name, fmt_data,
strlen(fmt_data));
} else
printer(printer_arg, te_lvl, comp_name,
&buffer[start_raw], te_len);
*start_pos = (old_start + te_len) % bufsize;
}
/* Look at the next entry too in order to return the new id. */
if (*start_pos != end_pos)
trace_entry_hdr_peek_buf(buffer, bufsize, *start_pos, start_id,
NULL,
NULL);
}
示例10: get_eth_conf
/* Builds up the correct configuration for vmdq+dcb based on the vlan tags array
* given above, and the number of traffic classes available for use. */
static inline int
get_eth_conf(struct rte_eth_conf *eth_conf)
{
struct rte_eth_vmdq_dcb_conf conf;
struct rte_eth_vmdq_rx_conf vmdq_conf;
struct rte_eth_dcb_rx_conf dcb_conf;
struct rte_eth_vmdq_dcb_tx_conf tx_conf;
uint8_t i;
conf.nb_queue_pools = (enum rte_eth_nb_pools)num_pools;
vmdq_conf.nb_queue_pools = (enum rte_eth_nb_pools)num_pools;
tx_conf.nb_queue_pools = (enum rte_eth_nb_pools)num_pools;
conf.nb_pool_maps = num_pools;
vmdq_conf.nb_pool_maps = num_pools;
conf.enable_default_pool = 0;
vmdq_conf.enable_default_pool = 0;
conf.default_pool = 0; /* set explicit value, even if not used */
vmdq_conf.default_pool = 0;
for (i = 0; i < conf.nb_pool_maps; i++) {
conf.pool_map[i].vlan_id = vlan_tags[i];
vmdq_conf.pool_map[i].vlan_id = vlan_tags[i];
conf.pool_map[i].pools = 1UL << i;
vmdq_conf.pool_map[i].pools = 1UL << i;
}
for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++){
conf.dcb_tc[i] = i % num_tcs;
dcb_conf.dcb_tc[i] = i % num_tcs;
tx_conf.dcb_tc[i] = i % num_tcs;
}
dcb_conf.nb_tcs = (enum rte_eth_nb_tcs)num_tcs;
(void)(rte_memcpy(eth_conf, &vmdq_dcb_conf_default, sizeof(*eth_conf)));
(void)(rte_memcpy(ð_conf->rx_adv_conf.vmdq_dcb_conf, &conf,
sizeof(conf)));
(void)(rte_memcpy(ð_conf->rx_adv_conf.dcb_rx_conf, &dcb_conf,
sizeof(dcb_conf)));
(void)(rte_memcpy(ð_conf->rx_adv_conf.vmdq_rx_conf, &vmdq_conf,
sizeof(vmdq_conf)));
(void)(rte_memcpy(ð_conf->tx_adv_conf.vmdq_dcb_tx_conf, &tx_conf,
sizeof(tx_conf)));
if (rss_enable) {
eth_conf->rxmode.mq_mode = ETH_MQ_RX_VMDQ_DCB_RSS;
eth_conf->rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP |
ETH_RSS_UDP |
ETH_RSS_TCP |
ETH_RSS_SCTP;
}
return 0;
}
示例11: qede_alloc_etherdev
static void
qede_alloc_etherdev(struct qede_dev *qdev, struct qed_dev_eth_info *info)
{
rte_memcpy(&qdev->dev_info, info, sizeof(*info));
qdev->num_tc = qdev->dev_info.num_tc;
qdev->ops = qed_ops;
}
示例12: addr_pton_cidr
int addr_pton_cidr(const char* p, struct xaddr* n, int* l) {
struct xaddr tmp;
int masklen = -1;
char addrbuf[64];
char* mp;
char* cp;
/* Don't modify argument */
if (p == NULL || strlcpy(addrbuf, p,
sizeof(addrbuf)) >= sizeof(addrbuf))
return (-1);
if ((mp = strchr(addrbuf, '/')) != NULL) {
*mp = '\0';
mp++;
masklen = (int) strtol(mp, &cp, 10);
if (*mp == '\0' || *cp != '\0' || masklen > 128)
return (-1);
}
if (addr_pton(addrbuf, &tmp) == -1)
return (-1);
if (mp == NULL)
masklen = addr_unicast_masklen(tmp.af);
if (addr_masklen_valid(tmp.af, masklen) == -1)
return (-1);
if (n != NULL)
rte_memcpy(n, &tmp, sizeof(*n));
if (l != NULL)
*l = masklen;
return (0);
}
示例13: qDebug
/**
* @brief Copy all mbuf segments to a buffer
*
* @param devId port number
* @param pMbuf mbuf
* @param data Data buffer
* @param dataLen Data buffer length
*
* @return true on success
*/
bool DPDKAdapter::copyMbufToBuf(uint8_t devId, MBuf_t* pMbuf, char* data, unsigned int& dataLen)
{
qDebug("pkt_len %u, data_len %u, nb_segs %u", pMbuf->pkt.pkt_len, pMbuf->pkt.data_len, pMbuf->pkt.nb_segs);
unsigned int segCnt = pMbuf->pkt.nb_segs;
unsigned int offset = 0;
MBuf_t* pNextMbuf = pMbuf;
dataLen = pMbuf->pkt.pkt_len;
while (segCnt > 0)
{
MBuf_t* pCurMbuf = pNextMbuf;
qDebug("segCnt %u, offset %u", segCnt, offset);
rte_memcpy(data + offset, pCurMbuf->pkt.data, pCurMbuf->pkt.data_len);
qDebug("pkt_len %u, data_len %u", pCurMbuf->pkt.pkt_len, pCurMbuf->pkt.data_len);
offset += pCurMbuf->pkt.data_len;
pNextMbuf = pCurMbuf->pkt.next;
rte_pktmbuf_free(pCurMbuf);
segCnt--;
}
return true;
}
示例14: rte_port_source_rx
static int
rte_port_source_rx(void *port, struct rte_mbuf **pkts, uint32_t n_pkts)
{
struct rte_port_source *p = port;
uint32_t i;
if (rte_pktmbuf_alloc_bulk(p->mempool, pkts, n_pkts) != 0)
return 0;
if (p->pkt_buff != NULL) {
for (i = 0; i < n_pkts; i++) {
uint8_t *pkt_data = rte_pktmbuf_mtod(pkts[i],
uint8_t *);
rte_memcpy(pkt_data, p->pkts[p->pkt_index],
p->pkt_len[p->pkt_index]);
pkts[i]->data_len = p->pkt_len[p->pkt_index];
pkts[i]->pkt_len = pkts[i]->data_len;
p->pkt_index++;
if (p->pkt_index >= p->n_pkts)
p->pkt_index = 0;
}
}
RTE_PORT_SOURCE_STATS_PKTS_IN_ADD(p, n_pkts);
return n_pkts;
}
示例15: pktgen_send_ping4
void
pktgen_send_ping4( uint32_t pid, uint8_t seq_idx )
{
port_info_t * info = &pktgen.info[pid];
pkt_seq_t * ppkt = &info->seq_pkt[PING_PKT];
pkt_seq_t * spkt = &info->seq_pkt[seq_idx];
struct rte_mbuf * m ;
uint8_t qid = 0;
m = rte_pktmbuf_alloc(info->q[qid].special_mp);
if ( unlikely(m == NULL) ) {
pktgen_log_warning("No packet buffers found");
return;
}
*ppkt = *spkt; // Copy the sequence setup to the ping setup.
pktgen_packet_ctor(info, PING_PKT, ICMP4_ECHO);
rte_memcpy((uint8_t *)m->buf_addr + m->data_off, (uint8_t *)&ppkt->hdr, ppkt->pktSize);
m->pkt_len = ppkt->pktSize;
m->data_len = ppkt->pktSize;
pktgen_send_mbuf(m, pid, qid);
pktgen_set_q_flags(info, qid, DO_TX_FLUSH);
}