3

I am new to Python and Mininet. I have been trying to emulate a network topology using mininet. I am trying to assign IP addresses to each of the hosts in the network but I'm getting an attribute error. Below is my code

import sys
from mininet.topo import Topo
from mininet.node import Node

class MyTopo(Topo):
    "customized topology example"
    def __init__(self):
        "custom topo creation"
        #initialize topology
        Topo.__init__(self)
        H1=self.addHost('H1')
        H3=self.addHost('H3')
        H2=self.addHost('H2')
        H4=self.addHost('H4')
        S1=self.addSwitch('S1')
        S2=self.addSwitch('S2')

        self.addLink(H1,S1, bw=10, delay='2ms')
        self.addLink(H2,S1, bw=20, delay='10ms')
        self.addLink(H3,S2, bw=10, delay='2ms')
        self.addLink(H4,S2, bw=20, delay='10ms')
        self.addLink(S1,S2, bw=20, delay='2ms', losspct=10)

        H1.setIP(self,None,'10.0.0.1',8)



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

I get the following error

Caught exception. Cleaning up...
AttributeError: 'str' object has no attribute 'setIp'
-----------------------------------------------------------------------   ---------
*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes
killall controller ofprotocol ofdatapath ping nox_core lt-nox_core ovs- openflowd ovs-controller udpbwtest mnexec ivs 2> /dev/null
killall -9 controller ofprotocol ofdatapath ping nox_core lt-nox_core ovs openflowd ovs-controller udpbwtest mnexec ivs 2> /dev/null
pkill -9 -f "sudo mnexec"
*** Removing junk from /tmp
rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log
*** Removing old X11 tunnels
*** Removing excess kernel datapaths                                                                                                                                                
ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'                                                                                                                                       
***  Removing OVS datapathsovs-vsctl --timeout=1 list-br                                                                                                                            
*** Removing all links of the pattern foo-ethX                                                                                                                                      
ip link show | egrep -o '(\w+-eth\w+)'                                                                                                                                              
*** Cleanup complete.   

Thanks

Curt cobain
  • 147
  • 1
  • 2
  • 8
  • try to add a `print(H1)` after `H1=self.addHost('H1')` and see what kind of thing it is. it seems to be a `str` – LittleByBlue Oct 12 '15 at 19:17
  • 1
    [It is indeed a string](http://mininet.org/api/classmininet_1_1topo_1_1Topo.html#a4649e48317e0b09f84ac5c6a88424194). I'm not familiar with mininet, but [looking at the documentation](http://mininet.org/api/classmininet_1_1node_1_1Node.html#a4f399c0b11eb6358b7b9997c612ad97a) it seems that the `setIP` method is defined on `Node` objects. – Andrea Corbellini Oct 12 '15 at 19:20

3 Answers3

2

The problem is, that

mininet.topo.Topo.addHost

does return the Hostname(you passed to the method). So you will have to use sth. like this:

self.addHost('H1')
selg.g.node['H1'].addLink(...) # maybe the part with the node['H1'] does not fit perfectly...

Take a look at this for further info.

Hint use a lot of print() s to get debug info. Eg:

debug=True
if(debug):print(someinfo)

Edit:

maybe you might want to use

mininet.topo.Multigraph.add_edge

for this.

LittleByBlue
  • 436
  • 9
  • 18
1

H1 is indeed a string. What you can do is get the net object for H1 and then try to set the IP.

net.get('H1').setIP(yourIP)

Anusha
  • 647
  • 11
  • 29
1

MyTopo is a class to define topology object. Host is an object attribute not a object in this instance. You can't use setIP method (of the host class) in this context.

You should set IP at the time you define the host:

 H1=self.addHost('H1', ip='10.0.0.1/8')