3

I have just set up a mininet topology. And now I want to connect one port on the switch in Mininet to an external port through an interface in Ubuntu. The Ubuntu server has two ports:

  • ens33 connected to a real network
  • ens38 connected to VMnet2

My Python script:

from mininet.net import Mininet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.link import Intf
from mininet.log import setLogLevel, info

from mininet.topo import Topo

class MyTopo( Topo ):
    "Simple topology example."

def __init__( self ):
    "Create custom topo."

    # Initialize topology
    Topo.__init__( self )

    # Add hosts and switches
    '*** Add switches\n'
    s1 = self.addSwitch('s1')
    Intf('ens38', node=s1)

    s2 = self.addSwitch('s2')

    '*** Add hosts\n'
    h2 = self.addHost('h2')
    # Add links
    '*** Add links\n'
    self.addLink(h2, s2)

topos = { 'mytopo': ( lambda: MyTopo() ) }

But when I run it with the following command line:

mn --custom qtho-topo.py --topo mytopo \
  --controller=remote,ip=192.168.1.128,port=6633 \
  --switch ovsk,protocols=OpenFlow13

There are errors:

Caught exception. Cleaning up...

AttributeError: 'str' object has no attribute 'addIntf'

Does anyone have any experience with this?

kelvin
  • 1,421
  • 13
  • 28

2 Answers2

0

This question was asked a while ago, but I hope my suggestion can be useful. The self.addSwitch() function returns a string, so s1 is a string, while the Intf function requires a Node type.

A simple solution, if you want to run it with the command line, is to create the network and then use a test function that adds the Interface, like the example below:

from mininet.net import Mininet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.link import Intf
from mininet.log import setLogLevel, info

from mininet.topo import Topo

class MyTopo( Topo ):
    "Simple topology example."

    def build( self ):
        "Create custom topo."

        # Add hosts and switches
        '*** Add switches\n'
        s1 = self.addSwitch('s1')
        info("**type s1 --> ", type(s1), "\n")

        s2 = self.addSwitch('s2')

        '*** Add hosts\n'
        h2 = self.addHost('h2')
        # Add links
        '*** Add links\n'
        self.addLink(h2, s2)

def addIface(mn):
    s1_node = mn.getNodeByName("s1")
    Intf("ens38", node=s1_node)
    CLI(mn)

tests = { 'addIf': addIface }
topos = { 'mytopo': ( lambda: MyTopo() ) }

To run it for the command line, assuming that you have named the file test.py:

mn --custom=test.py --topo=mytopo --test=addIf
kelvin
  • 1,421
  • 13
  • 28
Giuseppe
  • 658
  • 1
  • 6
  • 14
  • Thanks for sharing. For me, it is "enp9s0" instead of "ens38". Your solution is runnable, but when I try to ping "h2" from outside Terminal, I couldn't `> h2 ping 1.1.1.1` inside "mininet" nor I couldn't `$ ping h2` from outside Terminal. Do I understand correctly? – Cloud Cho Jul 11 '23 at 21:14
  • I tried the code outside Virtual Machine with port connected to a real network. The code somehow broke Internet interface. Even I reboot the machine and (I tried https://askubuntu.com/questions/455736/remove-ifupdowneth0-connection, but not solve) , I couldn't recover Internet interface. Would you have any suggestion to fix? – Cloud Cho Jul 28 '23 at 16:42
0

Adding to Giuseppe's response, this code worked for me:

def addIface(mn):
    s1_node = mn.getNodeByName("s1")
    s1_node.attach("ens38")
    CLI(mn)
kelvin
  • 1,421
  • 13
  • 28