Example #1
0
    def connect_tap_to_bridge(self, bridge_name=None):
        """Connect a ns-3 tap device to the bridge.

        Parameters
        ----------
        bridge_name : str
            The bridge to connect the tap (and ns-3) device to.
        """
        if bridge_name is None:
            bridge_name = self.bridge_name

        ipr = IPRoute()

        logger.debug('Connect %s to bridge %s via %s', self.node.name, bridge_name, self.tap_name)
        ipr.link('add', ifname=self.tap_name, kind='tuntap', mode='tap')
        defer(f'disconnect ns3 node {self.node.name}', self.disconnect_tap_from_bridge)

        ipr.link('set', ifname=self.tap_name, state='up')

        ipr.link('set', ifname=self.tap_name, master=ipr.link_lookup(ifname=bridge_name)[0])

        logger.debug("Adding TapBridge for %s.", self.node.name)
        tap_helper = tap_bridge.TapBridgeHelper()
        # ConfigureLocal is used to prevent the TAP / bridged device to use a "learned" MAC address.
        # So, we can set the CSMA and WiFiNetDevice address to something we control.
        # Otherwise, WiFi ACK misses happen.
        tap_helper.SetAttribute('Mode', core.StringValue('ConfigureLocal'))
        tap_helper.SetAttribute('DeviceName', core.StringValue(self.tap_name))
        tap_helper.SetAttribute('MacAddress', ns_net.Mac48AddressValue(ns_net.Mac48Address.Allocate()))
        tap_helper.Install(self.node.ns3_node, self.ns3_device)
Example #2
0
    def __init__(self, node, ns3_device, address, mac_address=None):
        #: A unique number identifying the interface.
        self.number = Interface.__counter
        Interface.__counter += 1

        #: The node to connect the interface to.
        self.node = node
        #: The ns-3 equivalent of the interface.
        self.ns3_device = ns3_device
        #: The interface's IP
        self.address = address
        #: The name of the interface. This will be set by in :func:`.Node.add_interface()`.
        self.ifname = None
        #: The MAC address of this interface.
        self.mac_address = mac_address
        if self.mac_address is None:
            allocated_mac = ns_net.Mac48Address.Allocate()
            checker = ns_net.MakeMac48AddressChecker()
            self.mac_address = ns_net.Mac48AddressValue(allocated_mac).SerializeToString(checker)