Beispiel #1
0
    def get_v4_nat_percentage(self):
        """
        :return: NAT % (percentage) for NAT 44
        """

        from app.caching.caching import cache as custom_cache
        from management.commands.set_caches import get_announcements
        announcements = custom_cache.get_or_set(
            custom_cache.keys.announcements,
            call=get_announcements
        )

        v4 = self.get_v4_results()

        # weigh by country
        total_region_ips = 0
        total_region_natted_ips = 0
        ccs = ['BB', 'KY', 'CU', 'DM', 'DO', 'GD', 'GP', 'HT', 'JM', 'BZ', 'AW', 'BS', 'SV', 'GT', 'HN', 'AR', 'BO',
               'BR', 'CL', 'GY', 'GF', 'EC', 'CO', 'LC', 'VC', 'TT', 'TC', 'VG', 'VI', 'MX', 'MS', 'PR', 'NI', 'PA',
               'PE', 'VE', 'UY', 'SR', 'PY', 'AI', 'AG', 'MQ', 'KN', 'CR',
               'FK']  # list(set([s.get_country() for s in v4]))  # unique countries only
        for cc in ccs:  # TODO only lac announcements
            if cc not in ccs:
                continue

            cc_msms = [s for s in v4 if s.get_country() == cc]
            cc_msms_natted = [s for s in cc_msms if s.is_natted(protocol=4)]
            if len(cc_msms_natted) == 0:
                continue

            adv = int(announcements[cc])  # announced prefixes
            cc_natted_ratio = 1.0 * len(cc_msms_natted) / len(cc_msms)
            adv_natted_ips = adv * cc_natted_ratio
            total_region_ips += adv
            total_region_natted_ips += adv_natted_ips

        return 100.0 * total_region_natted_ips / total_region_ips
Beispiel #2
0
def charts(request):
    """
    :param request:
    :return:
    """

    v6_avg_cached = custom_cache.get_or_set(custom_cache.keys.v6_avg, call=StunMeasurement.objects.v6_count_avg)
    v4_avg_cached = custom_cache.get_or_set(custom_cache.keys.v4_avg, call=StunMeasurement.objects.v4_count_avg)
    v6_max_cached = custom_cache.get_or_set(custom_cache.keys.v6_max, call=StunMeasurement.objects.v6_count_max)
    v4_max_cached = custom_cache.get_or_set(custom_cache.keys.v4_max, call=StunMeasurement.objects.v4_count_max)
    all_nat_cached = custom_cache.get_or_set(custom_cache.keys.all_nat, call=StunMeasurement.objects.nat_stats)
    v4_nat_cached = custom_cache.get_or_set(custom_cache.keys.v4_nat, call=StunMeasurement.objects.get_v4_nat_percentage)
    v6_nat_cached = custom_cache.get_or_set(custom_cache.keys.v6_nat, call=StunMeasurement.objects.get_v6_nat_percentage)
    v6_hosts_with_v4_capacity_cached = custom_cache.get_or_set(custom_cache.keys.v6_with_v4_capacity, call=StunMeasurement.objects.get_v6_hosts_with_v4_capability_percentage)
    dualstack_cached = custom_cache.get_or_set(custom_cache.keys.dualstack, call=StunMeasurement.objects.get_dualstack_percentage)
    is_npt_cached = custom_cache.get_or_set(custom_cache.keys.npt, call=StunMeasurement.objects.get_npt_percentage)
    nat_pressure_cached = custom_cache.get_or_set(custom_cache.keys.nat_pressure, call=StunMeasurement.objects.get_nat_time_pressure)
    country_participation_counter_cached = custom_cache.get_or_set(custom_cache.keys.country_participation, call=StunMeasurement.objects.get_country_participation)

    # Country participation chart

    total = sum(country_participation_counter_cached.values())
    most_common = country_participation_counter_cached.most_common(n=5)
    country_participation_top = [(p[0], 1.0 * p[1]) for p in most_common]
    country_participation_top.append(
        ("Others", 1.0 * (total - sum(p[1] for p in most_common)))
    )  # Others
    data = dict(
        data=json.dumps([[p[0] for p in country_participation_top], [p[1] for p in country_participation_top]]),
        divId="country-participation",
        labels=json.dumps(["Horas hasta ver un nuevo prefijo"]),
        kind='PieChart',
        colors=json.dumps(['#C53425', '#B21100', '#990F00', '#7F0C00', '#660A00', '#4C0700']),
        xAxis='string'
    )
    country_participation_chart = requests.post("https://charts.dev.lacnic.net/code/", data=data).text

    # NAT pressure chart

    hours = [int(1.0 * dt.seconds / (60 * 60)) for dt in nat_pressure_cached]
    data = dict(
        data=json.dumps(list(hours)),
        divId="div-id",
        labels=json.dumps(["Horas hasta ver un nuevo prefijo"]),
        colors=json.dumps(['#c53526']),
    )
    nat_pressure_chart = requests.post("https://charts.dev.lacnic.net/hist/code/", data=data).text

    ctx = RequestContext(
        request,
        {
            "v6_avg": v6_avg_cached,
            "v4_avg": v4_avg_cached,
            "v6_max": v6_max_cached,
            "v4_max": v4_max_cached,
            "all_nat": all_nat_cached,
            "v4_nat": v4_nat_cached,
            "v6_nat": v6_nat_cached,
            "v6_with_v4_capacity": v6_hosts_with_v4_capacity_cached,
            "dualstack": dualstack_cached,
            "npt": is_npt_cached,
            "hours": Counter(hours).most_common(n=1)[0][0],
            "nat_pressure_chart": nat_pressure_chart,
            "country_participation_chart": country_participation_chart
        }
    )

    return render_to_response("charts.html", ctx)