def test_015_qos_nobpass_custom_rules_tcp(self):
        global app
        nuke_rules()
        priority_level = 7

        # Record average speed without bandwidth control configured
        wget_speed_pre = global_functions.get_download_speed()

        # Create SRC_ADDR based custom Q0S rule to limit bypass QoS
        netsettings = copy.deepcopy(orig_network_settings_with_qos)
        netsettings['qosSettings']['qosRules']["list"].append(
            create_qos_custom_rule("SRC_ADDR", remote_control.clientIP,
                                   priority_level))
        uvmContext.networkManager().setNetworkSettings(netsettings)

        # Download file and record the average speed in which the file was download
        wget_speed_post = global_functions.get_download_speed()

        # Restore original network settings
        uvmContext.networkManager().setNetworkSettings(
            orig_network_settings_with_qos)

        # Because the session is NOT bypassed, the QoS rule should not take effect
        print_results(wget_speed_pre, wget_speed_post, wget_speed_pre * 0.1,
                      wget_speed_pre * limited_acceptance_ratio)

        assert ((wget_speed_pre) and (wget_speed_post))
        assert (
            not (wget_speed_pre * limited_acceptance_ratio > wget_speed_post))
    def test_020_severely_limited_tcp(self):
        global app
        nuke_rules()
        priority_level = 7
        # Record average speed without bandwidth control configured
        wget_speed_pre = global_functions.get_download_speed()

        # Create SRC_ADDR based rule to limit bandwidth
        append_rule(
            create_single_condition_rule("SRC_ADDR", remote_control.clientIP,
                                         "SET_PRIORITY", priority_level))

        # Download file and record the average speed in which the file was download
        wget_speed_post = global_functions.get_download_speed()

        print_results(wget_speed_pre, wget_speed_post, wget_speed_pre * 0.1,
                      wget_speed_pre * limited_acceptance_ratio)

        assert ((wget_speed_post) and (wget_speed_post))
        assert (wget_speed_pre * limited_acceptance_ratio > wget_speed_post)

        events = global_functions.get_events('Bandwidth Control',
                                             'Prioritized Sessions', None, 5)
        assert (events != None)
        found = global_functions.check_events(events.get('list'), 5,
                                              "bandwidth_control_priority",
                                              priority_level, "c_client_addr",
                                              remote_control.clientIP)
        assert (found)
示例#3
0
    def test_048_contentLengthAddrRule(self):
        global app
        nukeRules()
        priority_level = 7

        # Record average speed without bandwidth control configured
        wget_speed_pre = global_functions.get_download_speed()
        
        # Create DST_ADDR based rule to limit bandwidth
        appendRule(createBandwidthSingleConditionRule("HTTP_CONTENT_LENGTH",">3000000","SET_PRIORITY",priority_level))

        # Download file and record the average speed in which the file was download
        wget_speed_post = global_functions.get_download_speed()

        printResults( wget_speed_pre, wget_speed_post, wget_speed_pre*0.1, wget_speed_pre*limitedAcceptanceRatio )

        assert ((wget_speed_post) and (wget_speed_post))
        assert (wget_speed_pre * limitedAcceptanceRatio >  wget_speed_post)

        events = global_functions.get_events('Bandwidth Control','Prioritized Sessions',None,5)
        assert(events != None)
        found = global_functions.check_events( events.get('list'), 5, 
                                            "bandwidth_control_priority", priority_level,
                                            "c_client_addr", remote_control.clientIP)
        assert( found )
示例#4
0
    def test_047_hostnameRule(self):
        global app
        nukeRules()
        priority_level = 7
        # This test might need web filter for http to start
        # Record average speed without bandwidth control configured
        wget_speed_pre = global_functions.get_download_speed()
        
        # Create HTTP_HOST based rule to limit bandwidth
        appendRule(createBandwidthSingleConditionRule("HTTP_HOST","test.untangle.com","SET_PRIORITY",priority_level))

        # Download file and record the average speed in which the file was download
        wget_speed_post = global_functions.get_download_speed()
        
        printResults( wget_speed_pre, wget_speed_post, wget_speed_pre*0.1, wget_speed_pre*limitedAcceptanceRatio )

        assert ((wget_speed_post) and (wget_speed_post))
        assert (wget_speed_pre * limitedAcceptanceRatio >  wget_speed_post)

        events = global_functions.get_events('Bandwidth Control','Prioritized Sessions',None,5)
        assert(events != None)
        found = global_functions.check_events( events.get('list'), 5, 
                                            "bandwidth_control_priority", priority_level,
                                            "c_client_addr", remote_control.clientIP)
        assert( found )
示例#5
0
    def test_035_dstAddrRule(self):
        global app
        nukeRules()
        priority_level = 7

        # Get the IP address of test.untangle.com.  We could hardcoded this IP.
        test_untangle_IP = socket.gethostbyname("test.untangle.com")
        
        # Record average speed without bandwidth control configured
        wget_speed_pre = global_functions.get_download_speed()
        
        # Create DST_ADDR based rule to limit bandwidth
        appendRule(createBandwidthSingleConditionRule("DST_ADDR",test_untangle_IP,"SET_PRIORITY",priority_level))

        # Download file and record the average speed in which the file was download
        wget_speed_post = global_functions.get_download_speed()

        printResults( wget_speed_pre, wget_speed_post, wget_speed_pre*0.1, wget_speed_pre*limitedAcceptanceRatio )

        assert ((wget_speed_post) and (wget_speed_post))
        assert (wget_speed_pre * limitedAcceptanceRatio >  wget_speed_post)

        events = global_functions.get_events('Bandwidth Control','Prioritized Sessions',None,5)
        assert(events != None)
        found = global_functions.check_events( events.get('list'), 5, 
                                            "bandwidth_control_priority", priority_level,
                                            "c_client_addr", remote_control.clientIP)
        assert( found )
示例#6
0
    def test_060_hostquota(self):
        if remote_control.quickTestsOnly:
            raise unittest2.SkipTest('Skipping a time consuming test')
        global app
        nukeRules()
        priority_level = 7 # Severely Limited 
        given_quota = 10000 # 10k 

        # Remove any existing quota
        uvmContext.hostTable().removeQuota(remote_control.clientIP)
        
        # Record average speed without bandwidth control configured
        wget_speed_pre = global_functions.get_download_speed()
        
        # Create rule to give quota
        appendRule(createBandwidthQuotaRule("HOST_HAS_NO_QUOTA","true","GIVE_HOST_QUOTA",given_quota))
        # Create penalty for exceeding quota
        appendRule(createBandwidthSingleConditionRule("HOST_QUOTA_EXCEEDED","true","SET_PRIORITY",priority_level))

        # Download the file so quota is exceeded
        global_functions.get_download_speed()

        # quota accounting occurs every 60 seconds, so we must wait at least 60 seconds
        time.sleep(60)

        # Download file and record the average speed in which the file was download
        wget_speed_post = global_functions.get_download_speed()
        
        printResults( wget_speed_pre, wget_speed_post, wget_speed_pre*0.1, wget_speed_pre*limitedAcceptanceRatio )

        # Remove quota
        uvmContext.hostTable().removeQuota(remote_control.clientIP)

        assert ((wget_speed_post) and (wget_speed_post))
        assert (wget_speed_pre * limitedAcceptanceRatio >  wget_speed_post)

        events = global_functions.get_events('Bandwidth Control','Quota Events',None,5)
        assert(events != None)
        found = global_functions.check_events( events.get('list'), 5, 
                                               "action", 1, #quota given
                                               "size", given_quota,
                                               "entity", remote_control.clientIP)
        assert(found)
        found = global_functions.check_events( events.get('list'), 5, 
                                               "action", 2, #quota exceeded
                                               "entity", remote_control.clientIP)
        assert(found)

        events = global_functions.get_events('Bandwidth Control','Prioritized Sessions',None,5)
        assert(events != None)
        found = global_functions.check_events( events.get('list'), 5, 
                                               "bandwidth_control_priority", priority_level,
                                               "c_client_addr", remote_control.clientIP)
        assert( found )
    def test_050_severely_limited_web_filter_flagged(self):
        global app, app_web_filter
        nuke_rules()
        pre_count = global_functions.get_app_metric_value(app, "prioritize")

        priority_level = 7
        # This test might need web filter for http to start
        # Record average speed without bandwidth control configured
        wget_speed_pre = global_functions.get_download_speed(
            download_server="test.untangle.com")

        # Create WEB_FILTER_FLAGGED based rule to limit bandwidth
        append_rule(
            create_single_condition_rule("WEB_FILTER_FLAGGED", "true",
                                         "SET_PRIORITY", priority_level))

        # Test.untangle.com is listed as Software, Hardware in web filter. As of 1/2014 its in Technology
        settingsWF = app_web_filter.getSettings()
        i = 0
        untangleCats = ["Software,", "Technology"]
        for webCategories in settingsWF['categories']['list']:
            if any(x in webCategories['name'] for x in untangleCats):
                settingsWF['categories']['list'][i]['flagged'] = "true"
            i += 1
        app_web_filter.setSettings(settingsWF)

        # Download file and record the average speed in which the file was download
        wget_speed_post = global_functions.get_download_speed(
            download_server="test.untangle.com")

        print_results(wget_speed_pre, wget_speed_post, wget_speed_pre * 0.1,
                      wget_speed_pre * limited_acceptance_ratio)

        assert ((wget_speed_post) and (wget_speed_post))
        assert (wget_speed_pre * limited_acceptance_ratio > wget_speed_post)

        events = global_functions.get_events('Bandwidth Control',
                                             'Prioritized Sessions', None, 5)
        assert (events != None)
        found = global_functions.check_events(events.get('list'), 5,
                                              "bandwidth_control_priority",
                                              priority_level, "c_client_addr",
                                              remote_control.clientIP)
        assert (found)

        # Check to see if the faceplate counters have incremented.
        post_count = global_functions.get_app_metric_value(app, "prioritize")
        assert (pre_count < post_count)
    def test_012_qos_limit(self):
        global pre_down_speed_kbit, wan_limit_kbit

        print("\nSetting WAN limit: %i Kbps" % (wan_limit_kbit))

        post_down_speed_kbit = global_functions.get_download_speed()

        # since the limit is 90% of first measure, check that second measure is less than first measure
        assert (pre_down_speed_kbit > post_down_speed_kbit)
示例#9
0
    def test_012_qosLimit(self):
        global preDownSpeedKbsec, wanLimitKbit

        print "\nSetting WAN limit: %i Kbps" % (wanLimitKbit)

        postDownSpeedKbsec = global_functions.get_download_speed()

        # since the limit is 90% of first measure, check that second measure is less than first measure
        assert (preDownSpeedKbsec >  postDownSpeedKbsec)
    def initialSetUp(self):
        global app, app_web_filter, orig_network_settings, orig_network_settings_with_qos, orig_network_settings_without_qos, pre_down_speed_kbit, wan_limit_kbit, wan_limit_mbit
        if (uvmContext.appManager().isInstantiated(self.appName())):
            raise Exception('app %s already instantiated' % self.appName())
        app = uvmContext.appManager().instantiate(self.appName(),
                                                  default_policy_id)
        settings = app.getSettings()
        settings["configured"] = True
        app.setSettings(settings)
        app.start()
        if (uvmContext.appManager().isInstantiated(self.appNameWF())):
            raise Exception('app %s already instantiated' % self.appNameWF())
        app_web_filter = uvmContext.appManager().instantiate(
            self.appNameWF(), default_policy_id)
        if orig_network_settings == None:
            orig_network_settings = uvmContext.networkManager(
            ).getNetworkSettings()

        # disable QoS
        netsettings = copy.deepcopy(orig_network_settings)
        netsettings['qosSettings']['qosEnabled'] = False
        uvmContext.networkManager().setNetworkSettings(netsettings)

        # measure speed
        pre_down_speed_kbit = global_functions.get_download_speed(
            download_server="test.untangle.com")

        # calculate QoS limits
        wan_limit_kbit = int((pre_down_speed_kbit * 8) * .9)
        # set max to 100Mbit, so that other limiting factors dont interfere
        if wan_limit_kbit > 100000: wan_limit_kbit = 100000
        wan_limit_mbit = round(wan_limit_kbit / 1024, 2)
        # turn on QoS and set wan speed limits
        netsettings = copy.deepcopy(orig_network_settings)
        netsettings['qosSettings']['qosEnabled'] = True
        i = 0
        for interface in netsettings['interfaces']['list']:
            if interface['isWan']:
                netsettings['interfaces']['list'][i][
                    'downloadBandwidthKbps'] = wan_limit_kbit
                netsettings['interfaces']['list'][i][
                    'uploadBandwidthKbps'] = wan_limit_kbit
            i += 1
        netsettings['bypassRules']['list'] = []
        netsettings['qosSettings']['qosRules']['list'] = []

        # These store the "new" defaults with and without QoS
        orig_network_settings_with_qos = copy.deepcopy(netsettings)
        orig_network_settings_with_qos['qosSettings']['qosEnabled'] = True
        orig_network_settings_without_qos = copy.deepcopy(netsettings)
        orig_network_settings_without_qos['qosSettings']['qosEnabled'] = False

        uvmContext.networkManager().setNetworkSettings(
            orig_network_settings_with_qos)
示例#11
0
    def test_013_qosBypassCustomRules(self):
        global app
        nukeRules()
        priority_level = 7
        # Record average speed without bandwidth control configured
        wget_speed_pre = global_functions.get_download_speed()

        # Create SRC_ADDR based custom Q0S rule to limit bypass QoS
        netsettings = copy.deepcopy( origNetworkSettingsWithQoS )
        netsettings['qosSettings']['qosRules']["list"].append( createQoSCustomRule("SRC_ADDR",remote_control.clientIP,priority_level) )
        netsettings['bypassRules']['list'].append( createBypassConditionRule("SRC_ADDR",remote_control.clientIP) )
        uvmContext.networkManager().setNetworkSettings( netsettings )
        
        # Download file and record the average speed in which the file was download
        wget_speed_post = global_functions.get_download_speed()

        # Restore original network settings
        uvmContext.networkManager().setNetworkSettings( origNetworkSettingsWithQoS )
        
        printResults( wget_speed_pre, wget_speed_post, wget_speed_pre*0.1, wget_speed_pre*limitedAcceptanceRatio )

        assert ((wget_speed_pre) and (wget_speed_post))
        assert (wget_speed_pre * limitedAcceptanceRatio >  wget_speed_post)
示例#12
0
    def initialSetUp(self):
        global app, appWF, origNetworkSettings, origNetworkSettingsWithQoS, origNetworkSettingsWithoutQoS, preDownSpeedKbsec, wanLimitKbit, wanLimitMbit
        if (uvmContext.appManager().isInstantiated(self.appName())):
            raise Exception('app %s already instantiated' % self.appName())
        app = uvmContext.appManager().instantiate(self.appName(), defaultRackId)
        settings = app.getSettings()
        settings["configured"] = True
        app.setSettings(settings)        
        app.start()
        if (uvmContext.appManager().isInstantiated(self.appNameWF())):
            raise Exception('app %s already instantiated' % self.appNameWF())
        appWF = uvmContext.appManager().instantiate(self.appNameWF(), defaultRackId)
        if origNetworkSettings == None:
            origNetworkSettings = uvmContext.networkManager().getNetworkSettings()

        # disable QoS
        netsettings = copy.deepcopy( origNetworkSettings )
        netsettings['qosSettings']['qosEnabled'] = False
        uvmContext.networkManager().setNetworkSettings( netsettings )

        # measure speed
        preDownSpeedKbsec = global_functions.get_download_speed()

        # calculate QoS limits
        wanLimitKbit = int((preDownSpeedKbsec*8) * .9)
        # set max to 100Mbit, so that other limiting factors dont interfere
        if wanLimitKbit > 100000: wanLimitKbit = 100000 
        wanLimitMbit = round(wanLimitKbit/1024,2)
        # turn on QoS and set wan speed limits
        netsettings = copy.deepcopy( origNetworkSettings )
        netsettings['qosSettings']['qosEnabled'] = True
        i = 0
        for interface in netsettings['interfaces']['list']:
            if interface['isWan']:
                netsettings['interfaces']['list'][i]['downloadBandwidthKbps']=wanLimitKbit
                netsettings['interfaces']['list'][i]['uploadBandwidthKbps']=wanLimitKbit
            i += 1
        netsettings['bypassRules']['list'] = []
        netsettings['qosSettings']['qosRules']['list'] = []

        # These store the "new" defaults with and without QoS
        origNetworkSettingsWithQoS = copy.deepcopy( netsettings )
        origNetworkSettingsWithQoS['qosSettings']['qosEnabled'] = True
        origNetworkSettingsWithoutQoS = copy.deepcopy( netsettings )
        origNetworkSettingsWithoutQoS['qosSettings']['qosEnabled'] = False
        
        uvmContext.networkManager().setNetworkSettings(origNetworkSettingsWithQoS)
    def test_061_user_quota(self):
        if remote_control.quickTestsOnly:
            raise unittest2.SkipTest('Skipping a time consuming test')
        global app
        nuke_rules()
        priority_level = 7  # Severely Limited
        given_quota = 10000  # 10k

        # Set this host's username
        username = remote_control.run_command("hostname -s", stdout=True)
        entry = uvmContext.hostTable().getHostTableEntry(
            remote_control.clientIP)
        entry['usernameDirectoryConnector'] = username
        uvmContext.hostTable().setHostTableEntry(remote_control.clientIP,
                                                 entry)

        # Remove any existing quota
        uvmContext.userTable().removeQuota(username)

        # Record average speed without bandwidth control configured
        wget_speed_pre = global_functions.get_download_speed()

        # Create rule to give quota
        append_rule(
            create_quota_rule("USER_HAS_NO_QUOTA", "true", "GIVE_USER_QUOTA",
                              given_quota))

        # Create penalty for exceeding quota
        append_rule(
            create_single_condition_rule("USER_QUOTA_EXCEEDED", "true",
                                         "SET_PRIORITY", priority_level))

        # Download the file so quota is exceeded
        global_functions.get_download_speed(meg=1)

        # quota accounting occurs every 60 seconds, so we must wait at least 60 seconds
        time.sleep(60)

        # Download file and record the average speed in which the file was download
        wget_speed_post = global_functions.get_download_speed()

        print_results(wget_speed_pre, wget_speed_post, wget_speed_pre * 0.1,
                      wget_speed_pre * limited_acceptance_ratio)

        # Remove quota
        uvmContext.userTable().removeQuota(username)

        # Blank username
        entry['usernameDirectoryConnector'] = None
        uvmContext.hostTable().setHostTableEntry(remote_control.clientIP,
                                                 entry)

        assert ((wget_speed_post) and (wget_speed_post))
        assert (wget_speed_pre * limited_acceptance_ratio > wget_speed_post)

        events = global_functions.get_events('Bandwidth Control',
                                             'Quota Events', None, 5)
        assert (events != None)
        found = global_functions.check_events(
            events.get('list'),
            5,
            "action",
            1,  #quota given
            "size",
            given_quota,
            "entity",
            username)
        assert (found)
        found = global_functions.check_events(
            events.get('list'),
            5,
            "action",
            2,  #quota exceeded
            "entity",
            username)
        assert (found)

        events = global_functions.get_events('Bandwidth Control',
                                             'Prioritized Sessions', None, 5)
        assert (events != None)
        found = global_functions.check_events(events.get('list'), 5,
                                              "bandwidth_control_priority",
                                              priority_level, "c_client_addr",
                                              remote_control.clientIP)
        assert (found)