Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonfontes committed Sep 26, 2017
1 parent ce9c01c commit e842ed7
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 109 deletions.
2 changes: 2 additions & 0 deletions examples/associationControl.py
Expand Up @@ -28,6 +28,8 @@ def topology():
ap3 = net.addAccessPoint('ap3', ssid='ssid-ap3', mode='g', channel='11', position='90,50,0')
c1 = net.addController('c1', controller=Controller)

net.propagationModel("logDistancePropagationLossModel", exp=5)

print "*** Configuring wifi nodes"
net.configureWifiNodes()

Expand Down
8 changes: 4 additions & 4 deletions examples/forwardingBySSID.py
Expand Up @@ -36,21 +36,21 @@ def topology():
sta3 = net.addStation('sta3', position='10,25,0')
sta4 = net.addStation('sta4', position='50,30,0')
sta5 = net.addStation('sta5', position='45,65,0')
ap1 = net.addAccessPoint('ap1', ssid="ssid,ssid1,ssid2,ssid3,ssid4", mode="g", channel="1", position='30,40,0')
ap1 = net.addAccessPoint('ap1', ssid=['ssid','ssid1','ssid2','ssid3','ssid4'], mode="g", channel="1", position='30,40,0')
c0 = net.addController('c0', controller=Controller, ip='127.0.0.1', port=6653)

print "*** Configuring wifi nodes"
net.configureWifiNodes()

"""uncomment to plot graph"""
net.plotGraph(max_x=100, max_y=100)

sta1.setRange(15)
sta2.setRange(15)
sta3.setRange(15)
sta4.setRange(15)
sta5.setRange(15)

"""uncomment to plot graph"""
net.plotGraph(max_x=100, max_y=100)

print "*** Starting network"
net.build()
c0.start()
Expand Down
8 changes: 4 additions & 4 deletions examples/handover.py
Expand Up @@ -14,10 +14,10 @@ def topology():
net = Mininet(controller=Controller, link=TCLink, accessPoint=OVSKernelAP)

print "*** Creating nodes"
sta1 = net.addStation('sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8')
sta2 = net.addStation('sta2', mac='00:00:00:00:00:03', ip='10.0.0.3/8')
ap1 = net.addAccessPoint('ap1', ssid='ssid-ap1', mode='g', channel='1', position='15,30,0')
ap2 = net.addAccessPoint('ap2', ssid='ssid-ap2', mode='g', channel='6', position='55,30,0')
sta1 = net.addStation('sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8', range=20)
sta2 = net.addStation('sta2', mac='00:00:00:00:00:03', ip='10.0.0.3/8', range=20)
ap1 = net.addAccessPoint('ap1', ssid='ssid-ap1', mode='g', channel='1', position='15,30,0', range=30)
ap2 = net.addAccessPoint('ap2', ssid='ssid-ap2', mode='g', channel='6', position='55,30,0', range=30)
c1 = net.addController('c1', controller=Controller)

print "*** Configuring wifi nodes"
Expand Down
2 changes: 1 addition & 1 deletion examples/propagationModel.py
Expand Up @@ -20,7 +20,7 @@ def topology():
c1 = net.addController('c1', controller=Controller)

"*** Available propagation models: friisPropagationLossModel, twoRayGroundPropagationLossModel, logDistancePropagationLossModel ***"
net.propagationModel('friisPropagationLossModel', sL=2)
net.propagationModel("logDistancePropagationLossModel", exp=4)

print "*** Configuring wifi nodes"
net.configureWifiNodes()
Expand Down
1 change: 0 additions & 1 deletion mininet/net.py
Expand Up @@ -363,7 +363,6 @@ def addCar(self, name, cls=None, **params):
mininetWiFi.addParameters(car, self.autoSetMacs, defaults)

carsta = self.addStation(name + 'STA')
carsta.params['range'] = car.params['range']

car.params['carsta'] = carsta
self.carsSTA.append(carsta)
Expand Down
17 changes: 17 additions & 0 deletions mininet/node.py
Expand Up @@ -107,6 +107,7 @@ def __init__(self, name, inNamespace=True, **params):
self.func = []
self.type = 'host'
self.isStationary = True
self.range = 0

# Make pylint happy
(self.shell, self.execed, self.pid, self.stdin, self.stdout,
Expand Down Expand Up @@ -265,6 +266,7 @@ def updateGraph(self):
def setRange(self, _range=0):
from mininet.wifiNet import mininetWiFi
self.params['range'] = _range
self.range = _range
if self.isStationary:
self.updateGraph()
mobility.parameters_()
Expand All @@ -275,6 +277,18 @@ def setRange(self, _range=0):
if plot2d.fig_exists():
plot2d.updateCircleRadius(self)

def setRange_(self, _range=0):
from mininet.wifiNet import mininetWiFi
self.params['range'] = _range
if self.isStationary:
self.updateGraph()
else:
if mininetWiFi.is3d:
pass
else:
if plot2d.fig_exists():
plot2d.updateCircleRadius(self)

def testPosition(self, pos):
pos = pos.split(',')
self.params['position'] = float(pos[0]), float(pos[1]), float(pos[2])
Expand Down Expand Up @@ -1415,6 +1429,9 @@ def start_(self, ap, wlan=None, aplist=None):

if(len(ap.params['ssid'])) > 1:
for i in range(1, len(ap.params['ssid'])):
ap.params['txpower'].append(ap.params['txpower'][0])
ap.params['antennaGain'].append(ap.params['antennaGain'][0])
ap.params['antennaHeight'].append(ap.params['antennaHeight'][0])
ssid = ap.params['ssid'][i]
cmd = cmd + ('\n')
cmd = cmd + ("\nbss=%s" % ap.params['wlan'][i])
Expand Down
11 changes: 5 additions & 6 deletions mininet/wifiLink.py
Expand Up @@ -2,7 +2,6 @@
author: Ramon Fontes (ramonrf@dca.fee.unicamp.br)
"""
import numpy as np
import random
import os
import re

Expand Down Expand Up @@ -415,7 +414,7 @@ def wpaFile(self, sta, ap, wlan):
cmd = cmd + ' phase2=\"autheap=MSCHAPV2\"\n'
cmd = cmd + '}'

fileName = str(sta) + '.staconf'
fileName = '%s_%s.staconf' % (sta.name, wlan)
os.system('echo \'%s\' > %s' % (cmd, fileName))

@classmethod
Expand All @@ -429,10 +428,10 @@ def associate_wpa(self, sta, ap, wlan):
"""
pidfile = "mn%d_%s_%s_wpa.pid" % (os.getpid(), sta.name, wlan)
self.wpaFile(sta, ap, wlan)
debug("wpa_supplicant -B -Dnl80211 -P %s -i %s -c %s.staconf\n"
% (pidfile, sta.params['wlan'][wlan], sta))
sta.pexec("wpa_supplicant -B -Dnl80211 -P %s -i %s -c %s.staconf"
% (pidfile, sta.params['wlan'][wlan], sta))
debug("wpa_supplicant -B -Dnl80211 -P %s -i %s -c %s_%s.staconf\n"
% (pidfile, sta.params['wlan'][wlan], sta.name, wlan))
sta.pexec("wpa_supplicant -B -Dnl80211 -P %s -i %s -c %s_%s.staconf"
% (pidfile, sta.params['wlan'][wlan], sta.name, wlan))

@classmethod
def associate_wep(self, sta, ap, wlan):
Expand Down
8 changes: 3 additions & 5 deletions mininet/wifiMobility.py
Expand Up @@ -138,11 +138,9 @@ def apOutOfRange(self, sta, ap, wlan):
"""
if ap == sta.params['associatedTo'][wlan]:
debug('iw dev %s disconnect\n' % sta.params['wlan'][wlan])
if self.available_range != {}:
sta.setRange(18)
if 'encrypt' in ap.params and 'ieee80211r' not in ap.params:
if ap.params['encrypt'][0] == 'wpa' or ap.params['encrypt'][0] == 'wpa2':
os.system('rm %s.staconf' % sta)
os.system('rm %s_%s.staconf' % (sta.name, wlan))
pidfile = "mn%d_%s_%s_wpa.pid" % (os.getpid(), sta.name, wlan)
os.system('pkill -f \'wpa_supplicant -B -Dnl80211 -P %s -i %s\'' % (pidfile, sta.params['wlan'][wlan]))
if os.path.exists(('/var/run/wpa_supplicant/%s' % sta.params['wlan'][wlan])) :
Expand Down Expand Up @@ -240,12 +238,12 @@ def handover(self, sta, ap, wlan):
cls.associate_infra(sta, ap, wlan)
self.updateAssociation(sta, ap, wlan)
if self.available_range != {}:
sta.setRange(self.available_range[sta.params['mode'][wlan]]/5)
sta.setRange_(self.available_range[sta.params['mode'][wlan]]/5)

@classmethod
def updateAssociation(self, sta, ap, wlan):
"""
Updates attributes regarding the association
Updates attributes regarding association
:param sta: station
:param ap: access point
Expand Down
139 changes: 55 additions & 84 deletions mininet/wifiNet.py
Expand Up @@ -76,15 +76,19 @@ def addParameters(self, node, autoSetMacs, params, mode='managed'):
node.params['mac'] = []
node.phyID = []

passwd = ("%s" % params.pop('passwd', {}))
if(passwd != "{}"):
passwd = passwd.split(',')
node.params['passwd'] = passwd
if 'passwd' in params:
node.params['passwd'] = []
if isinstance(params['passwd'], basestring):
node.params['passwd'].append(params['passwd'])
else:
node.params['passwd'] = params['passwd']

encrypt = ("%s" % params.pop('encrypt', {}))
if(encrypt != "{}"):
encrypt = encrypt.split(',')
node.params['encrypt'] = encrypt
if 'encrypt' in params:
node.params['encrypt'] = []
if isinstance(params['encrypt'], basestring):
node.params['encrypt'].append(params['encrypt'])
else:
node.params['encrypt'] = params['encrypt']

if (mode == 'managed'):
node.params['apsInRange'] = []
Expand Down Expand Up @@ -167,8 +171,6 @@ def addParameters(self, node, autoSetMacs, params, mode='managed'):
self.addParamsToNode(node)
if mode == 'managed':
self.appendAssociatedTo(node)
if 'ssid' not in node.params:
self.appendEncrypt(node, n, passwd, encrypt)

if mode == 'master':
if 'phywlan' in node.params:
Expand Down Expand Up @@ -201,14 +203,7 @@ def addParameters(self, node, autoSetMacs, params, mode='managed'):

# Range
if 'range' in params:
node.params['range'] = int(params['range'])
else:
if mode == 'master' or node.func[0] == 'ap':
value = deviceRange(node)
node.params['range'] = value.range
else:
value = deviceRange(node)
node.params['range'] = value.range - 15
node.setRange(params['range'])

if mode == 'master' or 'ssid' in node.params:
node.params['associatedStations'] = []
Expand All @@ -233,22 +228,13 @@ def addParameters(self, node, autoSetMacs, params, mode='managed'):
if 'mac' in params:
node.params['mac'][0] = params[ 'mac' ]

ssid = ("%s" % params.pop('ssid', {}))
ssid = ssid.split(',')
node.params['ssid'] = []
if(ssid[0] != "{}"):
if len(ssid) == 1:
node.params['ssid'].append(ssid[0])
if(encrypt != "{}"):
node.params['encrypt'].append(encrypt[0])
if(passwd != "{}"):
node.params['passwd'].append(passwd[0])
if 'ssid' in params:
node.params['ssid'] = []
if isinstance(params['ssid'], basestring):
node.params['ssid'].append(params['ssid'])
else:
for n in range(len(ssid)):
node.params['ssid'].append(ssid[n])
self.appendEncrypt(node, n, passwd, encrypt)
else:
node.params['ssid'].append(params[ 'ssid' ])
for ssid in params['ssid']:
node.params['ssid'].append(ssid)

@classmethod
def addParamsToNode(self, node):
Expand All @@ -265,19 +251,6 @@ def appendSNR(self, node):
if not self.enable_interference:
node.params['snr'].append(40)

@classmethod
def appendEncrypt(self, node, n, passwd, encrypt):
if(passwd != "{}"):
if len(passwd) == 1:
node.params['passwd'].append(passwd[0])
else:
node.params['passwd'].append(passwd[n])
if(encrypt != "{}"):
if len(encrypt) == 1:
node.params['encrypt'].append(encrypt[0])
else:
node.params['encrypt'].append(encrypt[n])

@classmethod
def appendRSSI(self, node):
if not self.enable_interference:
Expand All @@ -288,28 +261,22 @@ def addIpParamToNode(self, node, wlans=0, autoSetMacs=False, params=None, isVirt
if isVirtualIface:
node.params['ip'].append(node.params['ip'][0])
else:
ip = ("%s" % params.pop('ip', {}))
if(ip != "{}"):
ip = ip.split(',')
if 'ip' in params:
node.params['ip'] = []
for n in range(len(node.params['wlan'])):
node.params['ip'].append('0/0')
if len(ip) > n:
node.params['ip'][n] = ip[n]
if isinstance(params['ip'], basestring):
node.params['ip'].append(params['ip'])
else:
for ip in (node.params['ip']):
node.params['ip'].append(ip)
elif autoSetMacs:
node.params['ip'] = []
for n in range(wlans):
node.params['ip'].append('0/0')
node.params['ip'][n] = params[ 'ip' ]
else:
try:
for n in range(wlans):
node.params['ip'].append('0/0')
except:
node.params['ip'] = []
node.params['ip'].append(params[ 'ip' ])
for n in range(1, wlans):
node.params['ip'].append('0/0')
node.params['ip'] = []
for n in range(wlans):
node.params['ip'].append('')

@classmethod
def addMacParamToNode(self, node, wlans=0, autoSetMacs=False, params=None, isVirtualIface=False, macID=0):
Expand All @@ -318,14 +285,13 @@ def addMacParamToNode(self, node, wlans=0, autoSetMacs=False, params=None, isVir
new_mac[7] = str(macID)
node.params['mac'].append("".join(new_mac))
else:
mac = ("%s" % params.pop('mac', {}))
if(mac != "{}"):
mac = mac.split(',')
if 'mac' in params:
node.params['mac'] = []
for n in range(len(node.params['wlan'])):
node.params['mac'].append('')
if len(mac) > n:
node.params['mac'][n] = mac[n]
if isinstance(params['mac'], basestring):
node.params['mac'].append(params['mac'])
else:
for mac in (node.params['mac']):
node.params['mac'].append(mac)
elif autoSetMacs:
node.params['mac'] = []
for n in range(wlans):
Expand Down Expand Up @@ -411,10 +377,8 @@ def addTxPowerParamToNode(self, node, wlans=0, params=None, isVirtualIface=False

@classmethod
def countWiFiIfaces(self, params):
wlans = ("%s" % params.pop('wlans', {}))
if(wlans != "{}"):
wlans = int(wlans)
self.wifiRadios += int(wlans)
if 'wlans' in params:
self.wifiRadios += int(params['wlans'])
else:
wlans = 1
self.wifiRadios += 1
Expand Down Expand Up @@ -802,8 +766,8 @@ def configureAP(self, ap, wlanID=0, aplist=None):
if 'phywlan' in ap.params:
ap.params.pop("phywlan", None)

if ap.func[0] != 'ap':
ap.params['frequency'][wlan] = link.frequency(ap, 0)
#if ap.func[0] != 'ap':
ap.params['frequency'][wlan] = link.frequency(ap, 0)

if len(ap.params['ssid']) > 1 and wlan == 0:
break
Expand Down Expand Up @@ -1127,11 +1091,18 @@ def configureWifiNodes(self, stations, accessPoints, cars, switches, \
for wlan in range(0, len(node.params['wlan'])):
node.setTxPower_(node.params['wlan'][wlan], node.params['txpower'][wlan])
node.setAntennaGain_(node.params['wlan'][wlan], node.params['antennaGain'][wlan])
if not self.getSignalRange:
for node in nodes:
for wlan in range(0, len(node.params['channel'])):
if node.params['range'] == 33 or node.params['range'] == 18:
value = distanceByPropagationModel(node, wlan)
if not self.getSignalRange:
for node in nodes:
for wlan in range(0, len(node.params['wlan'])):
if node.range == 0:
if node.type == 'vehicle' and wlan == 1:
node = node.params['carsta']
wlan = 0
value = distanceByPropagationModel(node, wlan)
if node.type != 'ap' and node.func[0] != 'ap' and \
node.func[wlan] != 'mesh' and node.func[wlan] != 'adhoc':
node.params['range'] = int(value.dist)/5
else:
node.params['range'] = int(value.dist)

return stations, accessPoints
Expand Down Expand Up @@ -1188,12 +1159,12 @@ def autoAssociation(self, stations, accessPoints):
if node.type == 'vehicle' and wlan == 1:
node = node.params['carsta']
wlan = 0
node.setTxPower_(node.params['wlan'][wlan], node.params['txpower'][wlan])
node.setAntennaGain_(node.params['wlan'][wlan], node.params['antennaGain'][wlan])
#node.setTxPower_(node.params['wlan'][wlan], node.params['txpower'][wlan])
#node.setAntennaGain_(node.params['wlan'][wlan], node.params['antennaGain'][wlan])
#node.setAntennaHeight_(node.params['wlan'][wlan], node.params['antennaHeight'][wlan])
if not self.getSignalRange and self.enable_interference:
value = distanceByPropagationModel(node, wlan)
node.params['range'] = int(value.dist)
#if not self.getSignalRange and self.enable_interference:
# value = distanceByPropagationModel(node, wlan)
# node.params['range'] = int(value.dist)

ap = []
for node in accessPoints:
Expand Down

0 comments on commit e842ed7

Please sign in to comment.