Network emulation with hosts spawned in network namespaces.
| 112 | VERSION = "2.3.1b4" |
| 113 | |
| 114 | class Mininet( object ): |
| 115 | "Network emulation with hosts spawned in network namespaces." |
| 116 | |
| 117 | # pylint: disable=too-many-arguments |
| 118 | def __init__( self, topo=None, switch=OVSKernelSwitch, host=Host, |
| 119 | controller=DefaultController, link=Link, intf=Intf, |
| 120 | build=True, xterms=False, cleanup=False, ipBase='10.0.0.0/8', |
| 121 | inNamespace=False, |
| 122 | autoSetMacs=False, autoStaticArp=False, autoPinCpus=False, |
| 123 | listenPort=None, waitConnected=False ): |
| 124 | """Create Mininet object. |
| 125 | topo: Topo (topology) object or None |
| 126 | switch: default Switch class |
| 127 | host: default Host class/constructor |
| 128 | controller: default Controller class/constructor |
| 129 | link: default Link class/constructor |
| 130 | intf: default Intf class/constructor |
| 131 | ipBase: base IP address for hosts, |
| 132 | build: build now from topo? |
| 133 | xterms: if build now, spawn xterms? |
| 134 | cleanup: if build now, cleanup before creating? |
| 135 | inNamespace: spawn switches and controller in net namespaces? |
| 136 | autoSetMacs: set MAC addrs automatically like IP addresses? |
| 137 | autoStaticArp: set all-pairs static MAC addrs? |
| 138 | autoPinCpus: pin hosts to (real) cores (requires CPULimitedHost)? |
| 139 | listenPort: base listening port to open; will be incremented for |
| 140 | each additional switch in the net if inNamespace=False |
| 141 | waitConnected: wait for switches to Connect? |
| 142 | (False; True/None=wait indefinitely; time(s)=timed wait)""" |
| 143 | self.topo = topo |
| 144 | self.switch = switch |
| 145 | self.host = host |
| 146 | self.controller = controller |
| 147 | self.link = link |
| 148 | self.intf = intf |
| 149 | self.ipBase = ipBase |
| 150 | self.ipBaseNum, self.prefixLen = netParse( self.ipBase ) |
| 151 | hostIP = ( 0xffffffff >> self.prefixLen ) & self.ipBaseNum |
| 152 | # Start for address allocation |
| 153 | self.nextIP = hostIP if hostIP > 0 else 1 |
| 154 | self.inNamespace = inNamespace |
| 155 | self.xterms = xterms |
| 156 | self.cleanup = cleanup |
| 157 | self.autoSetMacs = autoSetMacs |
| 158 | self.autoStaticArp = autoStaticArp |
| 159 | self.autoPinCpus = autoPinCpus |
| 160 | self.numCores = numCores() |
| 161 | self.nextCore = 0 # next core for pinning hosts to CPUs |
| 162 | self.listenPort = listenPort |
| 163 | self.waitConn = waitConnected |
| 164 | |
| 165 | self.hosts = [] |
| 166 | self.switches = [] |
| 167 | self.controllers = [] |
| 168 | self.links = [] |
| 169 | |
| 170 | self.nameToNode = {} # name to Node (Host/Switch) objects |
| 171 |
no outgoing calls