Revision 54037995

View differences:

bin/mn_run.py
100 100
        opts.add_option('--xterms', '-x', action = 'store_true',
101 101
                        default = False, help = 'spawn xterms for each node')
102 102
        opts.add_option('--mac', action = 'store_true',
103
                        default = False, help = 'set host MACs equal to DPIDs')
103
                        default = False, help = 'set MACs equal to DPIDs')
104 104
        opts.add_option('--arp', action = 'store_true',
105 105
                        default = False, help = 'set all-pairs ARP entries')
106 106
        opts.add_option('--verbosity', '-v', type = 'choice',
mininet/net.py
53 53
from time import sleep
54 54

  
55 55
from mininet.logging_mod import lg
56
from mininet.node import KernelSwitch
56 57
from mininet.util import quietRun, fixLimits
57 58
from mininet.util import make_veth_pair, move_intf, retry, MOVEINTF_DELAY
58 59
from mininet.xterm import cleanUpScreens, makeXterms
......
79 80

  
80 81
    def __init__(self, topo, switch, host, controller, cparams,
81 82
                 build = True, xterms = False, cleanup = False,
82
                 in_namespace = False, switch_is_kernel = True,
83
                 in_namespace = False,
83 84
                 auto_set_macs = False, auto_static_arp = False):
84 85
        '''Create Mininet object.
85 86

  
......
92 93
        @param xterms if build now, spawn xterms?
93 94
        @param cleanup if build now, cleanup before creating?
94 95
        @param in_namespace spawn switches and hosts in their own namespace?
95
        @param switch_is_kernel is the switch kernel-based?
96 96
        @param auto_set_macs set MAC addrs to DPIDs?
97 97
        @param auto_static_arp set all-pairs static MAC addrs?
98 98
        '''
......
105 105
        self.controllers = {} # controller name to Controller objects
106 106
        self.dps = 0 # number of created kernel datapaths
107 107
        self.in_namespace = in_namespace
108
        self.switch_is_kernel = switch_is_kernel
109 108
        self.xterms = xterms
110 109
        self.cleanup = cleanup
111 110
        self.auto_set_macs = auto_set_macs
......
130 129
        #lg.info('%s ' % host.name)
131 130

  
132 131
    def _add_switch(self, dpid):
133
        '''
132
        '''Add switch.
133

  
134 134
        @param dpid DPID of switch to add
135 135
        '''
136 136
        sw = None
137
        if self.switch_is_kernel:
138
            sw = self.switch('s_' + self.topo.name(dpid), 'nl:' + str(self.dps))
137
        sw_dpid = None
138
        if self.auto_set_macs:
139
            sw_dpid = dpid
140
        if self.switch is KernelSwitch:
141
            sw = self.switch('s_' + self.topo.name(dpid), dp = self.dps,
142
                             dpid = sw_dpid)
139 143
            self.dps += 1
140 144
        else:
141 145
            sw = self.switch('s_' + self.topo.name(dpid))
mininet/node.py
292 292

  
293 293
class KernelSwitch(Switch):
294 294

  
295
    def __init__(self, name, datapath = None):
295
    def __init__(self, name, dp = None, dpid = None):
296 296
        '''Init.
297 297

  
298 298
        @param name
299
        @param datapath string, datapath name
299
        @param dp netlink id (0, 1, 2, ...)
300
        @param dpid datapath ID as unsigned int; random value if None
300 301
        '''
301
        self.dp = datapath
302
        Node.__init__(self, name, inNamespace = (datapath == None))
302
        Node.__init__(self, name, inNamespace = False)
303
        self.dp = dp
304
        self.dpid = dpid
303 305

  
304 306
    def start(self, ignore):
305 307
        '''Start up reference kernel datapath.'''
......
307 309
        quietRun('ifconfig lo up')
308 310
        # Delete local datapath if it exists;
309 311
        # then create a new one monitoring the given interfaces
310
        quietRun('dpctl deldp ' + self.dp)
311
        self.cmdPrint('dpctl adddp ' + self.dp)
312
        self.cmdPrint('dpctl addif ' + self.dp + ' ' + ' '.join(self.intfs))
312
        quietRun('dpctl deldp nl:%i' % self.dp)
313
        self.cmdPrint('dpctl adddp nl:%i' % self.dp)
314
        if self.dpid:
315
            intf = 'of%i' % self.dp
316
            mac_str = macColonHex(self.dpid)
317
            self.cmd(['ifconfig', intf, 'hw', 'ether', mac_str])
318
        self.cmdPrint('dpctl addif nl:' + str(self.dp) + ' ' +
319
                      ' '.join(self.intfs))
313 320
        # Run protocol daemon
314
        self.cmdPrint('ofprotocol' +
315
                      ' ' + self.dp + ' tcp:127.0.0.1 ' +
321
        self.cmdPrint('ofprotocol nl:' + str(self.dp) + ' tcp:127.0.0.1 ' +
316 322
                      ' --fail=closed 1> ' + ofplog + ' 2>' + ofplog + ' &')
317 323
        self.execed = False # XXX until I fix it
318 324

  
319 325
    def stop(self):
320 326
        '''Terminate reference kernel datapath.'''
321
        quietRun('dpctl deldp ' + self.dp)
327
        quietRun('dpctl deldp nl:%i' % self.dp)
322 328
        # In theory the interfaces should go away after we shut down.
323 329
        # However, this takes time, so we're better off to remove them
324 330
        # explicitly so that we won't get errors if we run before they
mininet/topo.py
324 324

  
325 325
        self.k = k
326 326

  
327
        self._add_node(0, Node())
328
        hosts = range(1, k + 1)
327
        self._add_node(1, Node())
328
        hosts = range(2, k + 2)
329 329
        for h in hosts:
330 330
            self._add_node(h, Node(is_switch = False))
331
            self._add_edge(h, 0, Edge())
331
            self._add_edge(h, 1, Edge())
332 332

  
333 333
        if enable_all:
334 334
            self.enable_all()
......
347 347

  
348 348
        self.k = k
349 349

  
350
        switches = range(0, k)
350
        switches = range(1, k + 1)
351 351
        for s in switches:
352 352
            h = s + k
353 353
            self._add_node(s, Node())
354 354
            self._add_node(h, Node(is_switch = False))
355 355
            self._add_edge(s, h, Edge())
356 356
        for s in switches:
357
            if s != k - 1:
357
            if s != k:
358 358
                self._add_edge(s, s + 1, Edge())
359 359

  
360 360
        if enable_all:
mininet/util.py
177 177
    setrlimit( RLIMIT_NPROC, (4096, 8192))
178 178
    setrlimit( RLIMIT_NOFILE, (16384, 32768))
179 179

  
180

  
181
def _colonHex(val, bytes):
182
    '''Generate colon-hex string.
183

  
184
    @param val input as unsigned int
185
    @param bytes number of bytes to convert
186
    @return ch_str colon-hex string
187
    '''
188
    pieces = []
189
    for i in range (bytes - 1, -1, -1):
190
        pieces.append('%02x' % (((0xff << (i * 8)) & val) >> (i * 8)))
191
    ch_str = ':'.join(pieces)
192
    return ch_str
193

  
194

  
180 195
def macColonHex(mac):
181 196
    '''Generate MAC colon-hex string from unsigned int.
182 197

  
183 198
    @param mac MAC address as unsigned int
184 199
    @return mac_str MAC colon-hex string
185 200
    '''
186
    mac_pieces = []
187
    for i in range (5, -1, -1):
188
        mac_pieces.append('%02x' % (((0xff << (i * 8)) & mac) >> (i * 8)))
189
    mac_str = ':'.join(mac_pieces)
190
    return mac_str
201
    return _colonHex(mac, 6)
202

  
191 203

  
192 204
def ipStr(ip):
193 205
    '''Generate IP address string

Also available in: Unified diff