Skip to content

Commit 31fedce

Browse files
committed
some code improvements
1 parent 73e3126 commit 31fedce

11 files changed

+50
-66
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
MININET = mininet-base/mininet/*.py
1+
MININET = mininet/mininet/*.py
22
MININET_WIFI = mn_wifi/*.py
33
TEST = mn_wifi/test/*.py
44
EXAMPLES = mn_wifi/examples/*.py

bin/mn

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if 'PYTHONPATH' in os.environ:
2424

2525
from mininet.clean import cleanup
2626
from mininet.log import lg, LEVELS, info, debug, warn, error, output
27-
from mininet.net import VERSION
27+
from mn_wifi.net import VERSION
2828
from mininet.net import Mininet
2929
from mininet.node import (Host, CPULimitedHost, Controller, OVSController,
3030
Ryu, NOX, RemoteController, findController,

examples/4address.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
def topology():
1515
"Create a network."
16-
net = Mininet_wifi( controller=Controller, link=wmediumd,
17-
wmediumd_mode=interference, configure4addr=True,
18-
autoAssociation=False )
16+
net = Mininet_wifi(controller=Controller, link=wmediumd,
17+
wmediumd_mode=interference, configure4addr=True,
18+
autoAssociation=False)
1919

2020
info("*** Creating nodes\n")
2121
ap1 = net.addAccessPoint('ap1', ssid="ap1-ssid", mode="g",
22-
channel="1", position='30,30,0')
22+
channel="1", position='30,30,0')
2323
ap2 = net.addAccessPoint('ap2', ssid="ap2-ssid", mode="g",
24-
channel="1", position='40,60,0')
24+
channel="1", position='40,60,0')
2525
ap3 = net.addAccessPoint('ap3', ssid="ap3-ssid", mode="g",
26-
channel="1", position='50,30,0')
26+
channel="1", position='50,30,0')
2727
sta1 = net.addStation('sta1', ip="192.168.0.1/24", position='31,32,0')
2828
sta2 = net.addStation('sta2', ip="192.168.0.2/24", position='32,34,0')
2929
sta3 = net.addStation('sta3', ip="192.168.0.3/24", position='41,62,0')

examples/meshAP.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from mininet.node import Controller
66
from mininet.log import setLogLevel, info
7-
from mn_wifi.node import OVSKernelAP
87
from mn_wifi.link import wmediumd, mesh
98
from mn_wifi.cli import CLI_wifi
109
from mn_wifi.net import Mininet_wifi

examples/miniedit.py

+37-48
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ def body(self, master):
273273
Label(self.leftfieldFrame, text="Default AP:").grid(row=3, sticky=E)
274274
self.apType = StringVar(self.leftfieldFrame)
275275
self.apTypeMenu = OptionMenu(self.leftfieldFrame, self.apType, "Open vSwitch Kernel Mode",
276-
"Indigo Virtual AP", "Userspace AP",
277-
"Userspace AP inNamespace")
276+
"Indigo Virtual AP", "Userspace AP",
277+
"Userspace AP inNamespace")
278278
self.switchTypeMenu.grid(row=3, column=1, sticky=W)
279279
apTypePref = self.prefValues['apType']
280280
if apTypePref == 'ivs':
@@ -290,7 +290,7 @@ def body(self, master):
290290
Label(self.leftfieldFrame, text="Mode:").grid(row=3, sticky=E)
291291
self.mode = StringVar(self.leftfieldFrame)
292292
self.modeMenu = OptionMenu(self.leftfieldFrame, self.mode, "g", "a",
293-
"b", "n")
293+
"b", "n")
294294
self.modeMenu.grid(row=3, column=1, sticky=W)
295295
modePref = self.prefValues['mode']
296296
if modePref == 'g':
@@ -508,11 +508,11 @@ def __init__(self, master, _title):
508508
buttonFrame.grid(row=1 , column=0, sticky='nswe')
509509

510510
okButton = Button(buttonFrame, width=8, text='OK', relief='groove',
511-
bd=4, command=self.okAction)
511+
bd=4, command=self.okAction)
512512
okButton.grid(row=0, column=0, sticky=E)
513513

514514
canlceButton = Button(buttonFrame, width=8, text='Cancel', relief='groove',
515-
bd=4, command=self.cancelAction)
515+
bd=4, command=self.cancelAction)
516516
canlceButton.grid(row=0, column=1, sticky=W)
517517

518518
def body(self, master):
@@ -680,14 +680,12 @@ def addInterface( self ):
680680
def apply(self):
681681
externalInterfaces = []
682682
for row in range(self.tableFrame.rows):
683-
if (len(self.tableFrame.get(row, 0)) > 0 and
684-
row > 0):
683+
if (len(self.tableFrame.get(row, 0)) > 0 and row > 0):
685684
externalInterfaces.append(self.tableFrame.get(row, 0))
686685
vlanInterfaces = []
687686
for row in range(self.vlanTableFrame.rows):
688-
if (len(self.vlanTableFrame.get(row, 0)) > 0 and
689-
len(self.vlanTableFrame.get(row, 1)) > 0 and
690-
row > 0):
687+
if (len(self.vlanTableFrame.get(row, 0)) > 0
688+
and len(self.vlanTableFrame.get(row, 1)) > 0 and row > 0):
691689
vlanInterfaces.append([self.vlanTableFrame.get(row, 0), self.vlanTableFrame.get(row, 1)])
692690
privateDirectories = []
693691
for row in range(self.mountTableFrame.rows):
@@ -863,14 +861,12 @@ def addInterface( self ):
863861
def apply(self):
864862
externalInterfaces = []
865863
for row in range(self.tableFrame.rows):
866-
if (len(self.tableFrame.get(row, 0)) > 0 and
867-
row > 0):
864+
if (len(self.tableFrame.get(row, 0)) > 0 and row > 0):
868865
externalInterfaces.append(self.tableFrame.get(row, 0))
869866
vlanInterfaces = []
870867
for row in range(self.vlanTableFrame.rows):
871868
if (len(self.vlanTableFrame.get(row, 0)) > 0 and
872-
len(self.vlanTableFrame.get(row, 1)) > 0 and
873-
row > 0):
869+
len(self.vlanTableFrame.get(row, 1)) > 0 and row > 0):
874870
vlanInterfaces.append([self.vlanTableFrame.get(row, 0), self.vlanTableFrame.get(row, 1)])
875871
privateDirectories = []
876872
for row in range(self.mountTableFrame.rows):
@@ -1048,12 +1044,11 @@ def apply(self):
10481044

10491045
dpid = self.dpidEntry.get()
10501046
if (self.defaultDpid(self.hostnameEntry.get()) is None
1051-
and len(dpid) == 0):
1047+
and len(dpid) == 0):
10521048
showerror(title="Error",
1053-
message= 'Unable to derive default datapath ID - '
1054-
'please either specify a DPID or use a '
1055-
'canonical switch name such as s23.' )
1056-
1049+
message= 'Unable to derive default datapath ID - '
1050+
'please either specify a DPID or use a '
1051+
'canonical switch name such as s23.' )
10571052

10581053
results = {'externalInterfaces':externalInterfaces,
10591054
'hostname':self.hostnameEntry.get(),
@@ -1148,8 +1143,9 @@ def body(self, master):
11481143
# Selection of authentication
11491144
Label(self.leftfieldFrame, text="Authentication:").grid(row=rowCount, sticky=E)
11501145
self.authentication = StringVar(self.leftfieldFrame)
1151-
self.authenticationMenu = OptionMenu(self.leftfieldFrame, self.authentication, "none", "WEP",
1152-
"WPA", "WPA2")
1146+
self.authenticationMenu = OptionMenu(self.leftfieldFrame,
1147+
self.authentication, "none", "WEP",
1148+
"WPA", "WPA2")
11531149
self.authenticationMenu.grid(row=rowCount, column=1, sticky=W)
11541150
if 'authentication' in self.prefValues:
11551151
authPref = self.prefValues['authentication']
@@ -1295,10 +1291,9 @@ def apply(self):
12951291
if (self.defaultDpid(self.hostnameEntry.get()) is None
12961292
and len(dpid) == 0):
12971293
showerror(title="Error",
1298-
message= 'Unable to derive default datapath ID - '
1299-
'please either specify a DPID or use a '
1300-
'canonical switch name such as s23.' )
1301-
1294+
message= 'Unable to derive default datapath ID - '
1295+
'please either specify a DPID or use a '
1296+
'canonical switch name such as s23.' )
13021297

13031298
results = {'externalInterfaces':externalInterfaces,
13041299
'hostname':self.hostnameEntry.get(),
@@ -1871,7 +1866,7 @@ def updateScrollRegion( self ):
18711866
bbox = self.canvas.bbox( 'all' )
18721867
if bbox is not None:
18731868
self.canvas.configure( scrollregion=( 0, 0, bbox[ 2 ],
1874-
bbox[ 3 ] ) )
1869+
bbox[ 3 ] ) )
18751870

18761871
def canvasx( self, x_root ):
18771872
"Convert root x coordinate to canvas coordinate."
@@ -2239,7 +2234,7 @@ def loadTopology( self ):
22392234
dx, dy = self.canvas.coords( self.widgetToItem[ dest] )
22402235

22412236
self.link = self.canvas.create_line( sx, sy, dx, dy, width=4,
2242-
fill='blue', tag='link' )
2237+
fill='blue', tag='link' )
22432238
c.itemconfig(self.link, tags=c.gettags(self.link)+('data',))
22442239
self.addLink( src, dest, linkopts=link['opts'] )
22452240
self.createDataLinkBindings()
@@ -3144,20 +3139,20 @@ def finishLink( self, event ):
31443139
target = self.findItem( x, y )
31453140
dest = self.itemToWidget.get( target, None )
31463141
if ( source is None or dest is None or source == dest
3147-
or dest in source.links or source in dest.links ):
3142+
or dest in source.links or source in dest.links ):
31483143
self.releaseNetLink( event )
31493144
return
31503145
# For now, don't allow hosts to be directly linked
31513146
stags = self.canvas.gettags( self.widgetToItem[ source ] )
31523147
dtags = self.canvas.gettags( target )
31533148
if (('Host' in stags and 'Host' in dtags) or
3154-
('Controller' in dtags and 'LegacyRouter' in stags) or
3155-
('Controller' in stags and 'LegacyRouter' in dtags) or
3156-
('Controller' in dtags and 'LegacySwitch' in stags) or
3157-
('Controller' in stags and 'LegacySwitch' in dtags) or
3158-
('Controller' in dtags and 'Host' in stags) or
3159-
('Controller' in stags and 'Host' in dtags) or
3160-
('Controller' in stags and 'Controller' in dtags)):
3149+
('Controller' in dtags and 'LegacyRouter' in stags) or
3150+
('Controller' in stags and 'LegacyRouter' in dtags) or
3151+
('Controller' in dtags and 'LegacySwitch' in stags) or
3152+
('Controller' in stags and 'LegacySwitch' in dtags) or
3153+
('Controller' in dtags and 'Host' in stags) or
3154+
('Controller' in stags and 'Host' in dtags) or
3155+
('Controller' in stags and 'Controller' in dtags)):
31613156
self.releaseNetLink( event )
31623157
return
31633158

@@ -3753,11 +3748,8 @@ def buildNodes( self, net):
37533748
else:
37543749
hostCls=Host
37553750
debug( hostCls, '\n' )
3756-
newHost = net.addHost( name,
3757-
cls=hostCls,
3758-
ip=ip,
3759-
defaultRoute=defaultRoute
3760-
)
3751+
newHost = net.addHost( name, cls=hostCls, ip=ip,
3752+
defaultRoute=defaultRoute )
37613753

37623754
# Set the CPULimitedHost specific options
37633755
if 'cores' in opts:
@@ -3803,11 +3795,8 @@ def buildNodes( self, net):
38033795
else:
38043796
hostCls=Host
38053797
debug( hostCls, '\n' )
3806-
newStation = net.addStation( name,
3807-
cls=hostCls,
3808-
ip=ip,
3809-
defaultRoute=defaultRoute
3810-
)
3798+
newStation = net.addStation( name, cls=hostCls,
3799+
ip=ip, defaultRoute=defaultRoute )
38113800

38123801
# Set the CPULimitedHost specific options
38133802
if 'cores' in opts:
@@ -3873,9 +3862,9 @@ def pathCheck( *args, **kwargs ):
38733862
for arg in args:
38743863
if not quietRun( 'which ' + arg ):
38753864
showerror(title="Error",
3876-
message= 'Cannot find required executable %s.\n' % arg +
3877-
'Please make sure that %s is installed ' % moduleName +
3878-
'and available in your $PATH.' )
3865+
message= 'Cannot find required executable %s.\n' % arg +
3866+
'Please make sure that %s is installed ' % moduleName +
3867+
'and available in your $PATH.' )
38793868

38803869
def buildLinks( self, net):
38813870
# Make links

examples/mobility.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from mininet.node import Controller
88
from mininet.log import setLogLevel, info
9-
from mn_wifi.node import OVSKernelAP
109
from mn_wifi.cli import CLI_wifi
1110
from mn_wifi.net import Mininet_wifi
1211

mn_wifi/link.py

-2
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,6 @@ def updateParams(cls, sta, ap, wlan):
11881188
def associate(cls, sta, ap, enable_wmediumd, enable_interference,
11891189
**params):
11901190
"Associate to Access Point"
1191-
if params['wlan'] == 0:
1192-
wlan = sta.ifaceToAssociate
11931191
if 'position' in sta.params:
11941192
cls.configureWirelessLink(sta, ap, enable_wmediumd,
11951193
enable_interference, **params)

mn_wifi/module.py

-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ def load_ifb(cls, wlans):
217217
def docker_config(cls, n_radios=0, nodes=None, dir='~/',
218218
ip='172.17.0.1', num=0, **params):
219219

220-
from mn_wifi.node import AccessPoint
221-
222220
file = cls.prefix + 'docker_mn-wifi.sh'
223221
os.system('rm %s' % file)
224222
os.system("echo '#!/bin/bash' >> %s" % file)

mn_wifi/net.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from mn_wifi.link import wirelessLink, wmediumd, Association, \
3434
_4address, TCWirelessLink, TCLinkWirelessStation, ITSLink, \
3535
wifiDirectLink, adhoc, mesh, physicalMesh, physicalWifiDirectLink
36-
from mn_wifi.devices import GetRate, GetRange, GetTxPower
36+
from mn_wifi.devices import GetRate, GetRange
3737
from mn_wifi.mobility import mobility
3838
from mn_wifi.plot import plot2d, plot3d, plotGraph
3939
from mn_wifi.module import module
@@ -47,6 +47,7 @@
4747

4848
VERSION = "2.2.2d1"
4949

50+
5051
class Mininet_wifi(Mininet):
5152

5253
def __init__(self, topo=None, switch=OVSKernelSwitch,

mn_wifi/node.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ def setCPUs( self, cores, mems=0 ):
13401340
# We have to do this here after we've specified
13411341
# cpus and mems
13421342
errFail( 'cgclassify -g cpuset:/%s %s' % (
1343-
self.name, self.pid ) )
1343+
self.name, self.pid ) )
13441344

13451345
def config( self, cpu=-1, cores=None, **params ):
13461346
"""cpu: desired overall system CPU fraction

mn_wifi/wmediumdConnector.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1113,8 +1113,8 @@ def send_pos_update(cls, pos):
11131113
posZ = pos.sta_pos[2]
11141114
time.sleep(0.1)
11151115
debug("%s Updating Pos of %s to x=%s, y=%s, z=%s\n" % (
1116-
w_cst.LOG_PREFIX, pos.staintf.get_mac(),
1117-
posX, posY, posZ))
1116+
w_cst.LOG_PREFIX, pos.staintf.get_mac(),
1117+
posX, posY, posZ))
11181118
cls.sock.send(cls.__create_pos_update_request(pos))
11191119
return cls.__parse_response(
11201120
w_cst.WSERVER_POS_UPDATE_RESPONSE_TYPE,

0 commit comments

Comments
 (0)