mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Add files via upload
This commit is contained in:
parent
798903b839
commit
c99aa1ed2d
238
LibreQoS.py
238
LibreQoS.py
@ -77,122 +77,126 @@ def createTestClientsPool(slash16, quantity):
|
||||
else:
|
||||
raise Exception
|
||||
|
||||
#Clients
|
||||
clientsList = []
|
||||
#Add arbitrary number of test clients in /16 subnet
|
||||
#clientsList = createTestClientsPool('100.64.X.X', 5)
|
||||
#Add specific test clients
|
||||
#clientsList.append((100, '100.65.1.1'))
|
||||
def refreshShapers():
|
||||
#Clients
|
||||
clientsList = []
|
||||
#Add arbitrary number of test clients in /16 subnet
|
||||
#clientsList = createTestClientsPool('100.64.X.X', 5)
|
||||
#Add specific test clients
|
||||
#clientsList.append((100, '100.65.1.1'))
|
||||
|
||||
#Bring in clients from UCRM if enabled
|
||||
if importFromUNMS:
|
||||
tempList = pullUNMSCustomers()
|
||||
for cust in tempList:
|
||||
downloadSpeed = cust['downloadSpeed']
|
||||
uploadSpeed = cust['uploadSpeed']
|
||||
for ipAddr in cust['deviceIPs']:
|
||||
if '/' in ipAddr:
|
||||
ipAddr = ipAddr.split('/')[0]
|
||||
#Use UCRM plan speed values to place into corresponding plan defined here in LibreQoS
|
||||
clientsList.append((ipAddr, downloadSpeed, uploadSpeed))
|
||||
#Bring in clients from UCRM if enabled
|
||||
if importFromUNMS:
|
||||
tempList = pullUNMSCustomers()
|
||||
for cust in tempList:
|
||||
downloadSpeed = cust['downloadSpeed']
|
||||
uploadSpeed = cust['uploadSpeed']
|
||||
for ipAddr in cust['deviceIPs']:
|
||||
if '/' in ipAddr:
|
||||
ipAddr = ipAddr.split('/')[0]
|
||||
#Use UCRM plan speed values to place into corresponding plan defined here in LibreQoS
|
||||
clientsList.append((ipAddr, downloadSpeed, uploadSpeed))
|
||||
|
||||
#Categorize Clients By IPv4 /16
|
||||
listOfSlash16SubnetsInvolved = []
|
||||
clientsListWithSubnet = []
|
||||
for customer in clientsList:
|
||||
ipAddr, downloadSpeed, uploadSpeed = customer
|
||||
dec1, dec2, dec3, dec4 = ipAddr.split('.')
|
||||
slash16 = dec1 + '.' + dec2 + '.0.0'
|
||||
if slash16 not in listOfSlash16SubnetsInvolved:
|
||||
listOfSlash16SubnetsInvolved.append(slash16)
|
||||
clientsListWithSubnet.append((ipAddr, downloadSpeed, uploadSpeed, slash16, dec1, dec2, dec3, dec4))
|
||||
#Clear Prior Configs
|
||||
clearPriorSettings(interfaceA, interfaceB)
|
||||
#InterfaceA
|
||||
parentIDFirstPart = 1
|
||||
srcOrDst = 'dst'
|
||||
classIDCounter = 101
|
||||
hashIDCounter = parentIDFirstPart + 1
|
||||
shell('tc qdisc replace dev ' + interfaceA + ' root handle ' + str(parentIDFirstPart) + ': htb default 1')
|
||||
shell('tc class add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ': classid ' + str(parentIDFirstPart) + ':1 htb rate '+ str(pipeBandwidthCapacityMbps) + 'mbit')
|
||||
for slash16 in listOfSlash16SubnetsInvolved:
|
||||
#X.X.0.0
|
||||
thisSlash16Dec1 = slash16.split('.')[0]
|
||||
thisSlash16Dec2 = slash16.split('.')[1]
|
||||
groupedCustomers = []
|
||||
for i in range(255):
|
||||
tempList = []
|
||||
for customer in clientsListWithSubnet:
|
||||
ipAddr, downloadSpeed, uploadSpeed, slash16, dec1, dec2, dec3, dec4 = customer
|
||||
if (dec1 == thisSlash16Dec1) and (dec2 == thisSlash16Dec2) and (dec4 == str(i)):
|
||||
tempList.append(customer)
|
||||
if len(tempList) > 0:
|
||||
groupedCustomers.append(tempList)
|
||||
shell('tc filter add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32')
|
||||
shell('tc filter add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ': prio 5 handle ' + str(hashIDCounter) + ': u32 divisor 256')
|
||||
thirdDigitCounter = 0
|
||||
handleIDSecond = 1
|
||||
while thirdDigitCounter <= 255:
|
||||
if len(groupedCustomers) > 0:
|
||||
currentCustomerList = groupedCustomers.pop()
|
||||
tempHashList = getHashList()
|
||||
for cust in currentCustomerList:
|
||||
ipAddr, downloadSpeed, uploadSpeed, slash16, dec1, dec2, dec3, dec4 = cust
|
||||
twoDigitHashString = hex(int(dec4)).replace('0x','')
|
||||
shell('tc class add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ':1 classid ' + str(parentIDFirstPart) + ':' + str(classIDCounter) + ' htb rate '+ str(downloadSpeed) + 'mbit ceil '+ str(downloadSpeed) + 'mbit prio 3')
|
||||
shell('tc qdisc add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ':' + str(classIDCounter) + ' ' + fqOrCAKE)
|
||||
shell('tc filter add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32 ht ' + str(hashIDCounter) + ':' + twoDigitHashString + ' match ip ' + srcOrDst + ' ' + ipAddr + ' flowid ' + str(parentIDFirstPart) + ':' + str(classIDCounter))
|
||||
classIDCounter += 1
|
||||
thirdDigitCounter += 1
|
||||
if (srcOrDst == 'dst'):
|
||||
startPointForHash = '16' #Position of dst-address in IP header
|
||||
elif (srcOrDst == 'src'):
|
||||
startPointForHash = '12' #Position of src-address in IP header
|
||||
shell('tc filter add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32 ht 800:: match ip ' + srcOrDst + ' '+ thisSlash16Dec1 + '.' + thisSlash16Dec2 + '.0.0/16 hashkey mask 0x000000ff at ' + startPointForHash + ' link ' + str(hashIDCounter) + ':')
|
||||
hashIDCounter += 1
|
||||
#InterfaceB
|
||||
parentIDFirstPart = hashIDCounter + 1
|
||||
hashIDCounter = parentIDFirstPart + 1
|
||||
srcOrDst = 'src'
|
||||
shell('tc qdisc replace dev ' + interfaceB + ' root handle ' + str(parentIDFirstPart) + ': htb default 1')
|
||||
shell('tc class add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ': classid ' + str(parentIDFirstPart) + ':1 htb rate '+ str(pipeBandwidthCapacityMbps) + 'mbit')
|
||||
for slash16 in listOfSlash16SubnetsInvolved:
|
||||
#X.X.0.0
|
||||
thisSlash16Dec1 = slash16.split('.')[0]
|
||||
thisSlash16Dec2 = slash16.split('.')[1]
|
||||
groupedCustomers = []
|
||||
for i in range(255):
|
||||
tempList = []
|
||||
for customer in clientsListWithSubnet:
|
||||
ipAddr, downloadSpeed, uploadSpeed, slash16, dec1, dec2, dec3, dec4 = customer
|
||||
if (dec1 == thisSlash16Dec1) and (dec2 == thisSlash16Dec2) and (dec4 == str(i)):
|
||||
tempList.append(customer)
|
||||
if len(tempList) > 0:
|
||||
groupedCustomers.append(tempList)
|
||||
shell('tc filter add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32')
|
||||
shell('tc filter add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ': prio 5 handle ' + str(hashIDCounter) + ': u32 divisor 256')
|
||||
thirdDigitCounter = 0
|
||||
handleIDSecond = 1
|
||||
while thirdDigitCounter <= 255:
|
||||
if len(groupedCustomers) > 0:
|
||||
currentCustomerList = groupedCustomers.pop()
|
||||
tempHashList = getHashList()
|
||||
for cust in currentCustomerList:
|
||||
ipAddr, downloadSpeed, uploadSpeed, slash16, dec1, dec2, dec3, dec4 = cust
|
||||
twoDigitHashString = hex(int(dec4)).replace('0x','')
|
||||
shell('tc class add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ':1 classid ' + str(parentIDFirstPart) + ':' + str(classIDCounter) + ' htb rate '+ str(uploadSpeed) + 'mbit ceil '+ str(uploadSpeed) + 'mbit prio 3')
|
||||
shell('tc qdisc add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ':' + str(classIDCounter) + ' ' + fqOrCAKE)
|
||||
shell('tc filter add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32 ht ' + str(hashIDCounter) + ':' + twoDigitHashString + ' match ip ' + srcOrDst + ' ' + ipAddr + ' flowid ' + str(parentIDFirstPart) + ':' + str(classIDCounter))
|
||||
classIDCounter += 1
|
||||
thirdDigitCounter += 1
|
||||
if (srcOrDst == 'dst'):
|
||||
startPointForHash = '16' #Position of dst-address in IP header
|
||||
elif (srcOrDst == 'src'):
|
||||
startPointForHash = '12' #Position of src-address in IP header
|
||||
shell('tc filter add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32 ht 800:: match ip ' + srcOrDst + ' '+ thisSlash16Dec1 + '.' + thisSlash16Dec2 + '.0.0/16 hashkey mask 0x000000ff at ' + startPointForHash + ' link ' + str(hashIDCounter) + ':')
|
||||
hashIDCounter += 1
|
||||
#Done
|
||||
today = date.today()
|
||||
d1 = today.strftime("%d/%m/%Y")
|
||||
print("Successful run completed at ", d1)
|
||||
print("Program complete")
|
||||
#Categorize Clients By IPv4 /16
|
||||
listOfSlash16SubnetsInvolved = []
|
||||
clientsListWithSubnet = []
|
||||
for customer in clientsList:
|
||||
ipAddr, downloadSpeed, uploadSpeed = customer
|
||||
dec1, dec2, dec3, dec4 = ipAddr.split('.')
|
||||
slash16 = dec1 + '.' + dec2 + '.0.0'
|
||||
if slash16 not in listOfSlash16SubnetsInvolved:
|
||||
listOfSlash16SubnetsInvolved.append(slash16)
|
||||
clientsListWithSubnet.append((ipAddr, downloadSpeed, uploadSpeed, slash16, dec1, dec2, dec3, dec4))
|
||||
#Clear Prior Configs
|
||||
clearPriorSettings(interfaceA, interfaceB)
|
||||
#InterfaceA
|
||||
parentIDFirstPart = 1
|
||||
srcOrDst = 'dst'
|
||||
classIDCounter = 101
|
||||
hashIDCounter = parentIDFirstPart + 1
|
||||
shell('tc qdisc replace dev ' + interfaceA + ' root handle ' + str(parentIDFirstPart) + ': htb default 1')
|
||||
shell('tc class add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ': classid ' + str(parentIDFirstPart) + ':1 htb rate '+ str(pipeBandwidthCapacityMbps) + 'mbit')
|
||||
for slash16 in listOfSlash16SubnetsInvolved:
|
||||
#X.X.0.0
|
||||
thisSlash16Dec1 = slash16.split('.')[0]
|
||||
thisSlash16Dec2 = slash16.split('.')[1]
|
||||
groupedCustomers = []
|
||||
for i in range(255):
|
||||
tempList = []
|
||||
for customer in clientsListWithSubnet:
|
||||
ipAddr, downloadSpeed, uploadSpeed, slash16, dec1, dec2, dec3, dec4 = customer
|
||||
if (dec1 == thisSlash16Dec1) and (dec2 == thisSlash16Dec2) and (dec4 == str(i)):
|
||||
tempList.append(customer)
|
||||
if len(tempList) > 0:
|
||||
groupedCustomers.append(tempList)
|
||||
shell('tc filter add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32')
|
||||
shell('tc filter add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ': prio 5 handle ' + str(hashIDCounter) + ': u32 divisor 256')
|
||||
thirdDigitCounter = 0
|
||||
handleIDSecond = 1
|
||||
while thirdDigitCounter <= 255:
|
||||
if len(groupedCustomers) > 0:
|
||||
currentCustomerList = groupedCustomers.pop()
|
||||
tempHashList = getHashList()
|
||||
for cust in currentCustomerList:
|
||||
ipAddr, downloadSpeed, uploadSpeed, slash16, dec1, dec2, dec3, dec4 = cust
|
||||
twoDigitHashString = hex(int(dec4)).replace('0x','')
|
||||
shell('tc class add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ':1 classid ' + str(parentIDFirstPart) + ':' + str(classIDCounter) + ' htb rate '+ str(downloadSpeed) + 'mbit ceil '+ str(downloadSpeed) + 'mbit prio 3')
|
||||
shell('tc qdisc add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ':' + str(classIDCounter) + ' ' + fqOrCAKE)
|
||||
shell('tc filter add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32 ht ' + str(hashIDCounter) + ':' + twoDigitHashString + ' match ip ' + srcOrDst + ' ' + ipAddr + ' flowid ' + str(parentIDFirstPart) + ':' + str(classIDCounter))
|
||||
classIDCounter += 1
|
||||
thirdDigitCounter += 1
|
||||
if (srcOrDst == 'dst'):
|
||||
startPointForHash = '16' #Position of dst-address in IP header
|
||||
elif (srcOrDst == 'src'):
|
||||
startPointForHash = '12' #Position of src-address in IP header
|
||||
shell('tc filter add dev ' + interfaceA + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32 ht 800:: match ip ' + srcOrDst + ' '+ thisSlash16Dec1 + '.' + thisSlash16Dec2 + '.0.0/16 hashkey mask 0x000000ff at ' + startPointForHash + ' link ' + str(hashIDCounter) + ':')
|
||||
hashIDCounter += 1
|
||||
#InterfaceB
|
||||
parentIDFirstPart = hashIDCounter + 1
|
||||
hashIDCounter = parentIDFirstPart + 1
|
||||
srcOrDst = 'src'
|
||||
shell('tc qdisc replace dev ' + interfaceB + ' root handle ' + str(parentIDFirstPart) + ': htb default 1')
|
||||
shell('tc class add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ': classid ' + str(parentIDFirstPart) + ':1 htb rate '+ str(pipeBandwidthCapacityMbps) + 'mbit')
|
||||
for slash16 in listOfSlash16SubnetsInvolved:
|
||||
#X.X.0.0
|
||||
thisSlash16Dec1 = slash16.split('.')[0]
|
||||
thisSlash16Dec2 = slash16.split('.')[1]
|
||||
groupedCustomers = []
|
||||
for i in range(255):
|
||||
tempList = []
|
||||
for customer in clientsListWithSubnet:
|
||||
ipAddr, downloadSpeed, uploadSpeed, slash16, dec1, dec2, dec3, dec4 = customer
|
||||
if (dec1 == thisSlash16Dec1) and (dec2 == thisSlash16Dec2) and (dec4 == str(i)):
|
||||
tempList.append(customer)
|
||||
if len(tempList) > 0:
|
||||
groupedCustomers.append(tempList)
|
||||
shell('tc filter add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32')
|
||||
shell('tc filter add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ': prio 5 handle ' + str(hashIDCounter) + ': u32 divisor 256')
|
||||
thirdDigitCounter = 0
|
||||
handleIDSecond = 1
|
||||
while thirdDigitCounter <= 255:
|
||||
if len(groupedCustomers) > 0:
|
||||
currentCustomerList = groupedCustomers.pop()
|
||||
tempHashList = getHashList()
|
||||
for cust in currentCustomerList:
|
||||
ipAddr, downloadSpeed, uploadSpeed, slash16, dec1, dec2, dec3, dec4 = cust
|
||||
twoDigitHashString = hex(int(dec4)).replace('0x','')
|
||||
shell('tc class add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ':1 classid ' + str(parentIDFirstPart) + ':' + str(classIDCounter) + ' htb rate '+ str(uploadSpeed) + 'mbit ceil '+ str(uploadSpeed) + 'mbit prio 3')
|
||||
shell('tc qdisc add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ':' + str(classIDCounter) + ' ' + fqOrCAKE)
|
||||
shell('tc filter add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32 ht ' + str(hashIDCounter) + ':' + twoDigitHashString + ' match ip ' + srcOrDst + ' ' + ipAddr + ' flowid ' + str(parentIDFirstPart) + ':' + str(classIDCounter))
|
||||
classIDCounter += 1
|
||||
thirdDigitCounter += 1
|
||||
if (srcOrDst == 'dst'):
|
||||
startPointForHash = '16' #Position of dst-address in IP header
|
||||
elif (srcOrDst == 'src'):
|
||||
startPointForHash = '12' #Position of src-address in IP header
|
||||
shell('tc filter add dev ' + interfaceB + ' parent ' + str(parentIDFirstPart) + ': prio 5 u32 ht 800:: match ip ' + srcOrDst + ' '+ thisSlash16Dec1 + '.' + thisSlash16Dec2 + '.0.0/16 hashkey mask 0x000000ff at ' + startPointForHash + ' link ' + str(hashIDCounter) + ':')
|
||||
hashIDCounter += 1
|
||||
#Done
|
||||
today = date.today()
|
||||
d1 = today.strftime("%d/%m/%Y")
|
||||
print("Successful run completed at ", d1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
refreshShapers()
|
||||
print("Program complete")
|
||||
|
Loading…
Reference in New Issue
Block a user