Revision 376bcba4 mininet/net.py

View differences:

mininet/net.py
79 79

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

  
85 86
        @param topo Topo object
......
91 92
        @param xterms if build now, spawn xterms?
92 93
        @param cleanup if build now, cleanup before creating?
93 94
        @param in_namespace spawn switches and hosts in their own namespace?
95
        @param switch_is_kernel is the switch kernel-based?
96
        @param auto_set_macs set MAC addrs to DPIDs?
97
        @param auto_static_arp set all-pairs static MAC addrs?
94 98
        '''
95 99
        self.topo = topo
96 100
        self.switch = switch
......
102 106
        self.dps = 0 # number of created kernel datapaths
103 107
        self.in_namespace = in_namespace
104 108
        self.switch_is_kernel = switch_is_kernel
109
        self.xterms = xterms
110
        self.cleanup = cleanup
111
        self.auto_set_macs = auto_set_macs
112
        self.auto_static_arp = auto_static_arp
105 113

  
106 114
        self.terms = [] # list of spawned xterm processes
107 115

  
108 116
        self.kernel = True #temporary!
109 117

  
110 118
        if build:
111
            self.build(xterms, cleanup)
119
            self.build()
112 120

  
113 121
    def _add_host(self, dpid):
114 122
        '''Add host.
......
249 257
            lg.info('%s ', host.name)
250 258
        lg.info('\n')
251 259

  
252
    def build(self, xterms, cleanup):
260
    def build(self):
253 261
        '''Build mininet.
254 262

  
255 263
        At the end of this function, everything should be connected and up.
256

  
257
        @param xterms spawn xterms on build?
258
        @param cleanup cleanup before creating?
259 264
        '''
260
        if cleanup:
265
        if self.cleanup:
261 266
            pass # cleanup
262 267
        # validate topo?
263 268
        kernel = self.kernel
......
289 294
        lg.info('*** Configuring hosts\n')
290 295
        self._config_hosts()
291 296

  
292
        if xterms:
297
        if self.xterms:
293 298
            self.start_xterms()
299
        if self.auto_set_macs:
300
            self.set_macs()
301
        if self.auto_static_arp:
302
            self.static_arp()
294 303

  
295 304
    def switch_nodes(self):
296 305
        '''Return switch nodes.'''
......
315 324
            os.kill(term.pid, signal.SIGKILL)
316 325
        cleanUpScreens()
317 326

  
327
    def set_macs(self):
328
        '''Set MAC addrs to correspond to datapath IDs on hosts.
329

  
330
        Assume that the host only has one interface.
331
        '''
332
        for dpid in self.topo.hosts():
333
            host_node = self.nodes[dpid]
334
            host_node.setMAC(host_node.intfs[0], dpid)
335

  
336
    def static_arp(self):
337
        '''Add all-pairs ARP entries to remove the need to handle broadcast.'''
338
        for src in self.topo.hosts():
339
            src_node = self.nodes[src]
340
            for dst in self.topo.hosts():
341
                if src != dst:
342
                    src_node.setARP(dst, dst)
343

  
318 344
    def start(self):
319 345
        '''Start controller and switches\n'''
320 346
        lg.info('*** Starting controller\n')

Also available in: Unified diff