64 bytes from 192.168.1.2: icmp_seq=3 ttl=254 time=23.3927 ms
64 bytes from 192.168.1.2: icmp_seq=4 ttl=254 time=24.2975 ms
64 bytes from 192.168.1.2: icmp_seq=5 ttl=254 time=17.7049 ms
+
+Example: testpmd memif loopback
+-------------------------------
+In this example we will create 2 memif ports connected into loopback.
+The situation is analogous to cross connecting 2 ports of the NIC by cable.
+
+To set the loopback, just use the same socket and id with different roles::
+
+ #./testpmd --vdev=net_memif0,role=master,id=0 --vdev=net_memif1,role=slave,id=0 -- -i
+
+Then start the communication::
+
+ testpmd> start tx_first
+
+Finally we can check port stats to see the traffic::
+
+ testpmd> show port stats all
+ testpmd> show port stats all
dev = elt->dev;
pmd = dev->data->dev_private;
if (((pmd->flags & ETH_MEMIF_FLAG_DISABLED) == 0) &&
- pmd->id == i->id) {
+ (pmd->id == i->id) && (pmd->role == MEMIF_ROLE_MASTER)) {
/* assign control channel to device */
cc->dev = dev;
pmd->cc = cc;
pmd->flags &= ~ETH_MEMIF_FLAG_CONNECTING;
pmd->flags &= ~ETH_MEMIF_FLAG_CONNECTED;
+ rte_spinlock_lock(&pmd->cc_lock);
if (pmd->cc != NULL) {
/* Clear control message queue (except disconnect message if any). */
for (elt = TAILQ_FIRST(&pmd->cc->msg_queue); elt != NULL; elt = next) {
"Failed to unregister control channel callback.");
}
}
+ rte_spinlock_unlock(&pmd->cc_lock);
/* unconfig interrupts */
for (i = 0; i < pmd->cfg.num_s2m_rings; i++) {
/* reset connection configuration */
memset(&pmd->run, 0, sizeof(pmd->run));
- MIF_LOG(DEBUG, "Disconnected.");
+ MIF_LOG(DEBUG, "Disconnected, id: %d, role: %s.", pmd->id,
+ (pmd->role == MEMIF_ROLE_MASTER) ? "master" : "slave");
}
static int
size = recvmsg(cc->intr_handle.fd, &mh, 0);
if (size != sizeof(memif_msg_t)) {
- MIF_LOG(DEBUG, "Invalid message size.");
- memif_msg_enq_disconnect(cc, "Invalid message size", 0);
+ MIF_LOG(DEBUG, "Invalid message size = %zd", size);
+ if (size > 0)
+ /* 0 means end-of-file, negative size means error,
+ * don't send further disconnect message in such cases.
+ */
+ memif_msg_enq_disconnect(cc, "Invalid message size", 0);
return -1;
}
MIF_LOG(DEBUG, "Received msg type: %u.", msg.type);
}
pmd->socket_filename = socket->filename;
- if (socket->listener != 0 && pmd->role == MEMIF_ROLE_SLAVE) {
- MIF_LOG(ERR, "Socket is a listener.");
- return -1;
- } else if ((socket->listener == 0) && (pmd->role == MEMIF_ROLE_MASTER)) {
- MIF_LOG(ERR, "Socket is not a listener.");
- return -1;
- }
-
TAILQ_FOREACH(elt, &socket->dev_queue, next) {
tmp_pmd = elt->dev->data->dev_private;
- if (tmp_pmd->id == pmd->id) {
- MIF_LOG(ERR, "Memif device with id %d already "
- "exists on socket %s",
- pmd->id, socket->filename);
+ if (tmp_pmd->id == pmd->id && tmp_pmd->role == pmd->role) {
+ MIF_LOG(ERR, "Two interfaces with the same id (%d) can "
+ "not have the same role.", pmd->id);
return -1;
}
}