diff --git a/flowspec/snmpstats.py b/flowspec/snmpstats.py index 7350b9528e6f8d97f0e5cd10a814ad5dae60b3d7..6de52041de516e2d5f322641ec8419e7582ca3af 100644 --- a/flowspec/snmpstats.py +++ b/flowspec/snmpstats.py @@ -372,8 +372,8 @@ def poll_snmp_statistics(): counter_null = {"ts": rule_last_updated.isoformat(), "value": null_measurement } counter_zero = {"ts": rule_last_updated.isoformat(), "value": zero_measurement } else: - counter_null = {"ts": rule_last_updated.isoformat(), "value": null_measurement, "value_counter": null_measurement } - counter_zero = {"ts": rule_last_updated.isoformat(), "value": zero_measurement, "value_counter": zero_measurement } + counter_null = {"ts": rule_last_updated.isoformat(), "value": null_measurement, "value_dropped": null_measurement } + counter_zero = {"ts": rule_last_updated.isoformat(), "value": zero_measurement, "value_dropped": zero_measurement } #logger.info("snmpstats: STATISTICS_PER_RULE ruleobj="+str(ruleobj)) #logger.info("snmpstats: STATISTICS_PER_RULE ruleobj.type="+str(type(ruleobj))) @@ -385,9 +385,9 @@ def poll_snmp_statistics(): if rule_status=="ACTIVE": try: if xtype==xtype_default: - counter = {"ts": nowstr, "value": newdata[flowspec_params_str][xtype]} + counter = {"ts": nowstr, "value": newdata[flowspec_params_str][xtype_default]} else: - counter = {"ts": nowstr, "value": newdata[flowspec_params_str][xtype], "value_counter": newdata[flowspec_params_str][xtype_default]} + counter = {"ts": nowstr, "value": newdata[flowspec_params_str][xtype_default], "value_dropped": newdata[flowspec_params_str][xtype]} counter_is_null = False except Exception as e: @@ -499,7 +499,7 @@ def add_initial_zero_value(rule_id, route_obj, zero_or_null=True): if xtype==xtype_default: counter = {"ts": nowstr, "value": zero_measurement } else: - counter = {"ts": nowstr, "value": zero_measurement, "value_counter": zero_measurement } + counter = {"ts": nowstr, "value": zero_measurement, "value_dropped": zero_measurement } samplecount = settings.SNMP_MAX_SAMPLECOUNT diff --git a/templates/flowspy/route_details.html b/templates/flowspy/route_details.html index 44e1f3913f975957f061a91b120919b785aa3f63..f05f4f718266dca7d3021235666aa4e842ce80e6 100644 --- a/templates/flowspy/route_details.html +++ b/templates/flowspy/route_details.html @@ -137,8 +137,14 @@ function myreloadPage() { <script src="{% static 'js/chartjs/chartjs-plugin-zoom.min.js' %}"></script> <script type="text/javascript"> -function plotGraph(data) +function plotGraph(route_then_action, data) { + var is_rate_limiting_rule = route_then_action.includes("rate-limit"); + var is_drop_rule = route_then_action.includes("discard") || route_then_action.includes("drop"); + var is_accept_rule = route_then_action.includes("accept"); + + // + var xdata = Array(); var ypkgdata = Array(); @@ -146,12 +152,12 @@ function plotGraph(data) var ybytesdata = Array(); var ybytesdatarel = Array(); - var yseenpkgdata = Array(); - var yseenpkgdatarel = Array(); - var yseenbytesdata = Array(); - var yseenbytesdatarel = Array(); + var ydroppedpkgdata = Array(); + var ydroppedpkgdatarel = Array(); + var ydroppedbytesdata = Array(); + var ydroppedbytesdatarel = Array(); - var yseen_available = false; + var ydropped_available = false; for (i=0; i<data["data"].length; i++) { var d = data["data"][data["data"].length - 1 - i]; @@ -172,21 +178,21 @@ function plotGraph(data) ybytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0; } - if (d.value_counter!=undefined) { - yseen_available=true + if (d.value_dropped!=undefined) { + ydropped_available=true - yseenpkgdata[i] = d.value_counter.packets; - yseenbytesdata[i] = d.value_counter.bytes; + ydroppedpkgdata[i] = d.value_dropped.packets; + ydroppedbytesdata[i] = d.value_dropped.bytes; if (i == 0) { - yseenpkgdatarel[i] = 0; - yseenbytesdatarel[i] = 0; + ydroppedpkgdatarel[i] = 0; + ydroppedbytesdatarel[i] = 0; } else { - delta = (yseenpkgdata[i]===undefined) ? undefined : (yseenpkgdata[i-1]===undefined) ? yseenpkgdata[i] : (yseenpkgdata[i] - yseenpkgdata[i-1]); - yseenpkgdatarel[i] = (delta===undefined || delta>=0) ? delta : 0; + delta = (ydroppedpkgdata[i]===undefined) ? undefined : (ydroppedpkgdata[i-1]===undefined) ? ydroppedpkgdata[i] : (ydroppedpkgdata[i] - ydroppedpkgdata[i-1]); + ydroppedpkgdatarel[i] = (delta===undefined || delta>=0) ? delta : 0; - bytesdelta = (yseenbytesdata[i]===undefined) ? undefined : (yseenbytesdata[i-1]===undefined) ? yseenbytesdata[i] : (yseenbytesdata[i] - yseenbytesdata[i-1]); - yseenbytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0; + bytesdelta = (ydroppedbytesdata[i]===undefined) ? undefined : (ydroppedbytesdata[i-1]===undefined) ? ydroppedbytesdata[i] : (ydroppedbytesdata[i] - ydroppedbytesdata[i-1]); + ydroppedbytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0; } @@ -205,73 +211,117 @@ function plotGraph(data) graphbytesabs.height = 20; graphbytesrel.width = 80; graphbytesrel.height = 20; + + // + + accept__borderColor = "#20ff20"; // green + accept__pointbackgroundColor = "#ccffcc"; // light green + accept__backgroundColor = "#ccffcc"; // light green + + drop__borderColor = "#ff2020"; // red + drop__pointbackgroundColor = "#ffcccc"; // light red + drop__backgroundColor = "#ffcccc"; // light red + + matched__borderColor = "#ffa500"; // orange + matched__pointbackgroundColor = "#ffff00"; // yellow + matched__backgroundColor = "#ffff00"; // yellow + + + if (is_drop_rule) { + matched_text = "matched and dropped"; + value1__borderColor = drop__borderColor; + value1__pointbackgroundColor = drop__pointbackgroundColor; + value1__backgroundColor = drop__backgroundColor; + } else if (is_accept_rule) { + matched_text = "matched and accepted"; + value1__borderColor = accept__borderColor; + value1__pointbackgroundColor = accept__pointbackgroundColor; + value1__backgroundColor = accept__backgroundColor; + } else { + matched_text = "matched"; + value1__borderColor = matched__borderColor; + value1__pointbackgroundColor = matched__pointbackgroundColor; + value1__backgroundColor = matched__backgroundColor; + } var ypkg_datasets = [{ - label: '# packets', + label: '# packets '+matched_text, data: ypkgdata, borderWidth: 2, - borderColor: "#3c37c6", - pointBackgroundColor: "#3c37c6", - backgroundColor: "#99bfff" + borderColor: value1__borderColor, + pointBackgroundColor: value1__pointbackgroundColor, + backgroundColor: value1__backgroundColor + //borderColor: "#3c37c6", + //pointBackgroundColor: "#3c37c6", + //backgroundColor: "#99bfff" }]; var ypkgrel_datasets = [{ - label: '# packets', + label: '# packets '+matched_text, data: ypkgdatarel, borderWidth: 2, - borderColor: "#c63737", - pointBackgroundColor: "#c63737", - backgroundColor: "#ff877a" + borderColor: value1__borderColor, + pointBackgroundColor: value1__pointbackgroundColor, + backgroundColor: value1__backgroundColor + //borderColor: "#c63737", + //pointBackgroundColor: "#c63737", + //backgroundColor: "#ff877a" }]; var ybytes_datasets = [{ - label: '# bytes', + label: '# bytes '+matched_text, data: ybytesdata, borderWidth: 2, - borderColor: "#3c37c6", - pointBackgroundColor: "#3c37c6", - backgroundColor: "#99bfff" + borderColor: value1__borderColor, + pointBackgroundColor: value1__pointbackgroundColor, + backgroundColor: value1__backgroundColor + //borderColor: "#3c37c6", + //pointBackgroundColor: "#3c37c6", + //backgroundColor: "#99bfff" }]; var ybytesrel_datasets = [{ - label: '# bytes', + label: '# bytes '+matched_text, data: ybytesdatarel, borderWidth: 2, - borderColor: "#c63737", - pointBackgroundColor: "#c63737", - backgroundColor: "#ff877a" + borderColor: value1__borderColor, + pointBackgroundColor: value1__pointbackgroundColor, + backgroundColor: value1__backgroundColor + //borderColor: "#c63737", + //pointBackgroundColor: "#c63737", + //backgroundColor: "#ff877a" }]; - if (yseen_available) { + if (ydropped_available) { ypkg_datasets.push({ - label: '# packets matched', - data: yseenpkgdata, + label: '# packets dropped', + data: ydroppedpkgdata, borderWidth: 2, - borderColor: "#cc37c6", - pointBackgroundColor: "#3c37c6", - backgroundColor: "#59bf6f" + borderColor: drop__borderColor, + pointBackgroundColor: drop__pointbackgroundColor, + backgroundColor: drop__backgroundColor }); ypkgrel_datasets.push({ - label: '# packets matched', - data: yseenpkgdatarel, + label: '# packets dropped', + data: ydroppedpkgdatarel, borderWidth: 2, - borderColor: "#c63737", - pointBackgroundColor: "#c63737", - backgroundColor: "#6f223a" + borderColor: drop__borderColor, + pointBackgroundColor: drop__pointbackgroundColor, + backgroundColor: drop__backgroundColor }); ybytes_datasets.push({ - label: '# bytes matched', - data: yseenbytesdata, + label: '# bytes dropped', + data: ydroppedbytesdata, borderWidth: 2, - borderColor: "#cc37c6", - pointBackgroundColor: "#3c37c6", - backgroundColor: "#59bf6f" + borderColor: drop__borderColor, + pointBackgroundColor: drop__pointbackgroundColor, + backgroundColor: drop__backgroundColor }); ybytesrel_datasets.push({ - label: '# bytes matched', - data: yseenbytesdatarel, + label: '# bytes dropped', + data: ydroppedbytesdatarel, borderWidth: 2, - borderColor: "#c63737", - pointBackgroundColor: "#c63737", - backgroundColor: "#6f223a" + borderColor: drop__borderColor, + pointBackgroundColor: drop__pointbackgroundColor, + backgroundColor: drop__backgroundColor }); } @@ -375,7 +425,7 @@ $(document).ready(function() { $("#traffic-plot-loading").text("No data, try later"); } else { $("#traffic-plot-loading").hide(); - plotGraph(data); + plotGraph("{{ route.get_then }}", data); } }); }); diff --git a/vnet_router/fod_vnet_router b/vnet_router/fod_vnet_router index a69da97f57ef3799514d3ca8c40920821663e6fe..f41566c6facea17cba81b845616aed6de6fbf31f 100755 --- a/vnet_router/fod_vnet_router +++ b/vnet_router/fod_vnet_router @@ -908,18 +908,48 @@ elif [ "$1" = "--process_ruleinfo" ]; then #arg ## if [ \( -z "$counter_values_drop" -o "$counter_values_drop" = "0 0" \) -a "$use_random_values" = 1 ]; then - old_random_value1="$(cat "/dev/shm/rule_random_counter-$cookie.val1")" - old_random_value2="$(cat "/dev/shm/rule_random_counter-$cookie.val2")" - [ -n "$old_random_value1" ] || old_random_value1=0 - [ -n "$old_random_value2" ] || old_random_value2=0 - random_value1=$(( $old_random_value1 + $RANDOM * $RANDOM )) - random_value2=$(( $old_random_value2 + $RANDOM * $RANDOM / 100 / 100 )) + store_file_prefix="/dev/shm/rule_random_counter-$cookie" - echo "$random_value1" > "/dev/shm/rule_random_counter-$cookie.val1" - echo "$random_value2" > "/dev/shm/rule_random_counter-$cookie.val2" + old_random_value_read_bytes="$(cat "$store_file_prefix-read-bytes.val")" + old_random_value_read_pkgs="$(cat "$store_file_prefix-read-pkgs.val")" + [ -n "$old_random_value_read_bytes" ] || old_random_value_read_bytes=0 + [ -n "$old_random_value_read_pkgs" ] || old_random_value_read_pkgs=0 + + random_value_add_read_bytes=$(( $RANDOM * $RANDOM )) + random_value_add_read_pkgs=$(( $RANDOM * $RANDOM / 100 / 100 )) + + random_value_read_bytes=$(( $old_random_value_read_bytes + $random_value_add_read_bytes )) + random_value_read_pkgs=$(( $old_random_value_read_pkgs + $random_value_add_read_pkgs )) + + echo "$random_value_read_bytes" > "$store_file_prefix-read-bytes.val" + echo "$random_value_read_pkgs" > "$store_file_prefix-read-pkgs.val" + + ## + + if [ "$then" = "${then#rate-limit}" ]; then # not a rate-limiting rule? + random_value_drop_bytes="$random_value_read_bytes" + random_value_drop_pkgs="$random_value_read_pkgs" + else + + old_random_value_drop_bytes="$(cat "$store_file_prefix-drop-bytes.val")" + old_random_value_drop_pkgs="$(cat "$store_file_prefix-drop-pkgs.val")" + [ -n "$old_random_value_drop_bytes" ] || old_random_value_drop_bytes=0 + [ -n "$old_random_value_drop_pkgs" ] || old_random_value_drop_pkgs=0 + + random_value_add_drop_bytes=$(( $RANDOM * $random_value_add_read_bytes / 32678 )) + random_value_add_drop_pkgs=$(( $RANDOM * $random_value_add_read_pkgs / 32678 )) + + random_value_drop_bytes=$(( $old_random_value_drop_bytes + $random_value_add_drop_bytes )) + random_value_drop_pkgs=$(( $old_random_value_drop_pkgs + $random_value_add_drop_pkgs )) + + echo "$random_value_drop_bytes" > "$store_file_prefix-drop-bytes.val" + echo "$random_value_drop_pkgs" > "$store_file_prefix-drop-pkgs.val" + + fi - counter_values_drop="$random_value1 $random_value2" + counter_values_read="$random_value_read_bytes $random_value_read_pkgs" + counter_values_drop="$random_value_drop_bytes $random_value_drop_pkgs" fi ##