aboutsummaryrefslogtreecommitdiffstats
path: root/extras/libmemif/README.md
diff options
context:
space:
mode:
authorTomas Slusny <slusnucky@gmail.com>2018-06-28 12:23:28 +0200
committerTomas Slusny <slusnucky@gmail.com>2018-07-02 12:20:29 +0200
commit3f26790b479f8a0cab00093b83491e9f47648b56 (patch)
treeed48b06e769bfb1bbacaad42ec1d73d079214811 /extras/libmemif/README.md
parent7c044e96ae66f2403e4d82005943a0f6d99bb6a7 (diff)
Add gopacket adapter for libmemif
Add simple PacketHandle adapter for gopacket PacketDataSource + add writePacketData convenience method to it. Change-Id: I2280db33076c497c9b63fd107b6d77ecf85dd23b Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
Diffstat (limited to 'extras/libmemif/README.md')
-rw-r--r--extras/libmemif/README.md61
1 files changed, 60 insertions, 1 deletions
diff --git a/extras/libmemif/README.md b/extras/libmemif/README.md
index 3b692b1..854aa96 100644
--- a/extras/libmemif/README.md
+++ b/extras/libmemif/README.md
@@ -103,6 +103,14 @@ Do not touch memif after it was closed, let garbage collector to remove
the `Memif` instance. In the end, `Cleanup()` will also ensure that all
active memif interfaces are closed before the cleanup finalizes.
+To use libmemif with `google/gopacket`, simply call `Memif.NewPacketHandle()`
+to create `google/gopacket/PacketDataSource` from memif queue. After this you
+can use gopacket API to read from `MemifPacketHandle` as normal. You can pass
+optional `rxCount` when creating the packet handle and then when reading data,
+handle will try to read more packets at once and cache them for next iteration.
+Handle also includes convenience method `MemifPacketHandle.WritePacketData()`
+that is simply calling 1 `Memif.TxBurst()` for provided data.
+
### Examples
**Go-libmemif** ships with two simple examples demonstrating the usage
@@ -185,4 +193,55 @@ vpp$ sh ip arp
It was actually converted to an ARP request. This is a VPP
specific feature common to all interface types.
-Stop the example with an interrupt signal (^C). \ No newline at end of file
+Stop the example with an interrupt signal (^C).
+
+#### GoPacket ICMP Responder
+
+*gopacket* is a simple example showing how to answer APR and ICMP echo
+requests through a memif interface. This example is mostly identical
+to icmp-responder example, but it is using MemifPacketHandle API to
+read and write packets using gopacket API.
+
+The appropriate VPP configuration for the opposite memif is:
+```
+vpp$ create memif socket id 1 filename /tmp/gopacket-example
+vpp$ create interface memif id 1 socket-id 1 slave secret secret no-zero-copy
+vpp$ set int state memif1/1 up
+vpp$ set int ip address memif1/1 192.168.1.2/24
+```
+
+To start the example, simply type:
+```
+root$ ./gopacket
+```
+
+gopacket needs to be run as root so that it can access the socket
+created by VPP.
+
+Normally, the memif interface is in the master mode. Pass CLI flag "--slave"
+to create memif in the slave mode:
+```
+root$ ./gopacket --slave
+```
+
+Don't forget to put the opposite memif into the master mode in that case.
+
+To verify the connection, run:
+```
+vpp$ ping 192.168.1.1
+64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=.6974 ms
+64 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=.6310 ms
+64 bytes from 192.168.1.1: icmp_seq=4 ttl=255 time=1.0350 ms
+64 bytes from 192.168.1.1: icmp_seq=5 ttl=255 time=.5359 ms
+
+Statistics: 5 sent, 4 received, 20% packet loss
+vpp$ sh ip arp
+Time IP4 Flags Ethernet Interface
+68.5648 192.168.1.1 D aa:aa:aa:aa:aa:aa memif0/1
+```
+
+*Note*: it is expected that the first ping is shown as lost.
+ It was actually converted to an ARP request. This is a VPP
+ specific feature common to all interface types.
+
+Stop the example with an interrupt signal (^C).