# system provided modules
import os, string, time, socket
+from socket import inet_aton
# PlanetLab system modules
import sioc, plnet
# local modules
-import bwlimitlxc as bwlimit
+import plnode.bwlimit as bwlimit
import logger, iptables, tools
+import subprocess
# we can't do anything without a network
priority=1
##################
plnet.InitInterfaces(logger, plc, data)
+
+ """
if 'OVERRIDES' in dir(config):
if config.OVERRIDES.get('net_max_rate') == '-1':
logger.log("net: Slice and node BW Limits disabled.")
InitNodeLimit(data)
InitI2(plc, data)
InitNAT(plc, data)
-
-
+ """
+
def InitNodeLimit(data):
# query running network interfaces
fields['source'] = "0.0.0.0/0"
ipt.add_pf(fields)
ipt.commit()
+
+# Helper functions for converting to CIDR notation
+def get_net_size(netmask):
+ binary_str = ''
+ for octet in netmask:
+ binary_str += bin(int(octet))[2:].zfill(8)
+ return str(len(binary_str.rstrip('0')))
+
+def to_cidr(ipaddr, netmask):
+ # validate input
+ inet_aton(ipaddr)
+ inet_aton(netmask)
+
+ ipaddr = ipaddr.split('.')
+ netmask = netmask.split('.')
+
+ net_start = [str(int(ipaddr[x]) & int(netmask[x])) for x in range(0,4)]
+ return '.'.join(net_start) + '/' + get_net_size(netmask)
+
+def ipaddr_range(network, broadcast):
+ start = network.split('.')
+ end = broadcast.split('.')
+
+ # Assume interface always claims the first address in the block
+ start[3] = str(int(start[3]) + 2)
+ end[3] = str(int(end[3]) - 1)
+
+ return '.'.join(start) + ',' + '.'.join(end)
+