Capturing traffic since network booting

To check the routing configuration of the network, it may be useful to capture the first messages exchanged by the network’s daemon. To do so, the capture needs to start before the network booting.

IPmininet proposes an overlay to declare a network capture directly inside the topology:

class ipmininet.overlay.NetworkCapture(nodes: List[NodeDescription] = (), interfaces: List[IntfDescription] = (), base_filename: str = 'capture', extra_arguments: str = '')

This overlays capture traffic on multiple interfaces before starting the daemons and stores the result

Parameters:
  • nodes – The routers and hosts that needs to capture traffic on every of their interfaces
  • interfaces – The interfaces on which traffic should be captured
  • base_filename – The base name of the network capture. One file by router or interface will be created of the form “{base_filename}_{router/interface}.pcapng” in the working directory of the node on which each capture is made.
  • extra_arguments – The string encoding any additional argument for the tcpdump call

We can add it with addNetworkCapture() method as shown in this example:

from ipmininet.iptopo import IPTopo
from ipmininet.utils import realIntfList


class MyTopology(IPTopo):
    """
       +----+                 +----+
       | r1 +-----------------+ r2 |
       +--+-+                 +-+--+
          |   +----+   +----+   |
          +---+ s1 +---+ s2 +---+
              +----+   +----+
    """

def build(self, *args, **kw):
    r1, r2 = self.addRouters('r1', 'r2')
    s1 = self.addSwitch('s1')
    s2 = self.addSwitch('s2')
    lr1r2, _, ls1s2, _ = self.addLinks((r1, r2), (r1, s1), (s1, s2), (s2, r2))

    self.addNetworkCapture(# Capture on all the interfaces of r1 and s1
                           nodes=[r1, s1],
                           # Capture on two specific interfaces of r2 and s2
                           interfaces=[lr1r2[r2], ls1s2[s2]],
                           # The prefix of the capture filename
                           base_filename="capture",
                           # Any additional argument to give to tcpdump
                           extra_arguments="-v")
    super().build(*args, **kw)