From e000a8a449c4061a6ecba0fedb5c9106940bdb12 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Thu, 20 Jul 2017 11:25:12 +1000 Subject: [PATCH 01/11] Update version --- ZodiacFX/src/config/config_zodiac.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/config/config_zodiac.h b/ZodiacFX/src/config/config_zodiac.h index bdfbe2c..f18236a 100644 --- a/ZodiacFX/src/config/config_zodiac.h +++ b/ZodiacFX/src/config/config_zodiac.h @@ -31,7 +31,7 @@ #define CONFIG_ZODIAC_H_ -#define VERSION "0.81" // Firmware version number +#define VERSION "0.82" // Firmware version number #define TOTAL_PORTS 4 // Total number of physical ports on the Zodiac FX From 861906f37f3c46c8ab6d503693cada7f3a4cc210 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Thu, 20 Jul 2017 11:25:31 +1000 Subject: [PATCH 02/11] Fix metering time delta calculation --- ZodiacFX/src/openflow/of_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index b7a9eef..818048d 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1311,7 +1311,7 @@ int meter_handler(uint32_t id, uint16_t bytes) } // Find time delta - uint64_t time_delta = sys_get_ms() - meter_entry[meter_index]->last_packet_in; + uint32_t time_delta = (uint32_t)(sys_get_ms() - meter_entry[meter_index]->last_packet_in); // Update timer meter_entry[meter_index]->last_packet_in = sys_get_ms(); From bcaaf235c87d0081b9094bdf1420967e6e3045fa Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Thu, 20 Jul 2017 13:23:14 +1000 Subject: [PATCH 03/11] Modify meter timer update Do not update if packet is dropped --- ZodiacFX/src/openflow/of_helper.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 818048d..7d60de7 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1313,15 +1313,12 @@ int meter_handler(uint32_t id, uint16_t bytes) // Find time delta uint32_t time_delta = (uint32_t)(sys_get_ms() - meter_entry[meter_index]->last_packet_in); - // Update timer - meter_entry[meter_index]->last_packet_in = sys_get_ms(); - // Check configuration flags uint32_t calculated_rate = 0; if(((meter_entry[meter_index]->flags) & OFPMF13_KBPS) == OFPMF13_KBPS) { calculated_rate = ((bytes*8)/time_delta); // bit/ms == kbit/s - TRACE("of_helper.c: calculated rate - %d kbps", calculated_rate); + TRACE("of_helper.c: calculated rate - %d kbps (%d bytes over %d ms)", calculated_rate, bytes, time_delta); } else if(((meter_entry[meter_index]->flags) & OFPMF13_PKTPS) == OFPMF13_PKTPS) { @@ -1359,6 +1356,10 @@ int meter_handler(uint32_t id, uint16_t bytes) if(highest_rate == 0 || ptr_highest_band == NULL) { TRACE("of_helper.c: no bands triggered - packet not dropped"); + + // Update timer + meter_entry[meter_index]->last_packet_in = sys_get_ms(); + return METER_NOACT; } From 1b391161672fee988d808f82fcc179b17c5631b8 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Thu, 20 Jul 2017 16:13:04 +1000 Subject: [PATCH 04/11] Fix flow match priority check (OF10) --- ZodiacFX/src/openflow/of_helper.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 7d60de7..e6052a1 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -208,7 +208,10 @@ int flowmatch10(uint8_t *pBuffer, int port, struct packet_fields *fields) } // If this flow is of a lower priority then one that is already match then there is no point going through a check. - if(ntohs(flow_match10[i]->priority) <= ntohs(flow_match10[matched_flow]->priority)) continue; + if (matched_flow > -1) + { + if(ntohs(flow_match10[i]->priority) <= ntohs(flow_match10[matched_flow]->priority)) continue; + } port_match = (ntohl(flow_match10[i]->match.wildcards) & OFPFW_IN_PORT) || ntohs(flow_match10[i]->match.in_port) == port || flow_match10[i]->match.in_port == 0; eth_src_match = (ntohl(flow_match10[i]->match.wildcards) & OFPFW_DL_SRC) || memcmp(eth_src, flow_match10[i]->match.dl_src, 6) == 0 || memcmp(flow_match10[i]->match.dl_src, zero_field, 6) == 0; @@ -249,7 +252,9 @@ int flowmatch10(uint8_t *pBuffer, int port, struct packet_fields *fields) if (matched_flow > -1) { if(ntohs(flow_match10[i]->priority) > ntohs(flow_match10[matched_flow]->priority)) matched_flow = i; - } else { + } + else + { matched_flow = i; } } From e884b5833eded9b608fee7e03207018e7d512710 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Sun, 23 Jul 2017 19:20:26 +1000 Subject: [PATCH 05/11] Add simple 12-sample rate limiter --- ZodiacFX/src/config/config_zodiac.h | 1 + ZodiacFX/src/openflow/of_helper.c | 80 +++++++++++++++++++++++------ ZodiacFX/src/openflow/openflow.h | 12 +++++ 3 files changed, 77 insertions(+), 16 deletions(-) diff --git a/ZodiacFX/src/config/config_zodiac.h b/ZodiacFX/src/config/config_zodiac.h index f18236a..9844d1e 100644 --- a/ZodiacFX/src/config/config_zodiac.h +++ b/ZodiacFX/src/config/config_zodiac.h @@ -52,5 +52,6 @@ #define MAX_METER_13 8 // Maximum number of meter entries in meter table #define MAX_METER_BANDS_13 3 // Maximum number of meter bands per meter +#define POLICING_SAMPLES 12 // Sample for rate limiter #endif /* CONFIG_ZODIAC_H_ */ diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index e6052a1..f57091d 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1279,7 +1279,11 @@ int flow_stats_msg13(char *buffer, int first, int last) * */ int meter_handler(uint32_t id, uint16_t bytes) -{ +{ + // Initialise 8x 12-element packet samples + static struct meter_sample_array meter_samples[MAX_METER_13]; + static uint8_t sample_index = 0; + TRACE("of_helper.c: meter id %d needs processing", id); // Get associated meter entry @@ -1304,30 +1308,77 @@ int meter_handler(uint32_t id, uint16_t bytes) // Update meter counters meter_entry[meter_index]->byte_in_count += bytes; (meter_entry[meter_index]->packet_in_count)++; + meter_entry[meter_index]->last_packet_in = sys_get_ms(); + + //// Check if meter has been used before + //if(meter_entry[meter_index]->last_packet_in == 0) + //{ + //// Update timer + //meter_entry[meter_index]->last_packet_in = sys_get_ms(); + // + //TRACE("of_helper.c: first hit of meter - packet not dropped"); + //return METER_NOACT; + //} - // Check if meter has been used before - if(meter_entry[meter_index]->last_packet_in == 0) + // Get current time + uint32_t current_time = (uint32_t)(sys_get_ms()); + + // Check if last packet was within 1 ms of this one + if(meter_samples[meter_index].sample[sample_index].packet_time == current_time) + { + meter_samples[meter_index].sample[sample_index].byte_count += bytes; + meter_samples[meter_index].sample[sample_index].packet_count++; + } + else { - // Update timer - meter_entry[meter_index]->last_packet_in = sys_get_ms(); + // Increment sample index + if(sample_index >= 11) + { + // Wrap sample_index around + sample_index = 0; + } + else + { + // Increment index + sample_index++; + } - TRACE("of_helper.c: first hit of meter - packet not dropped"); - return METER_NOACT; + // Populate (overwrite) next element + meter_samples[meter_index].sample[sample_index].packet_time = current_time; + meter_samples[meter_index].sample[sample_index].byte_count += bytes; + meter_samples[meter_index].sample[sample_index].packet_count++; } - // Find time delta - uint32_t time_delta = (uint32_t)(sys_get_ms() - meter_entry[meter_index]->last_packet_in); - // Check configuration flags uint32_t calculated_rate = 0; if(((meter_entry[meter_index]->flags) & OFPMF13_KBPS) == OFPMF13_KBPS) { - calculated_rate = ((bytes*8)/time_delta); // bit/ms == kbit/s - TRACE("of_helper.c: calculated rate - %d kbps (%d bytes over %d ms)", calculated_rate, bytes, time_delta); + // Calculate kbit/s from samples taken over last 10 ms + uint32_t sampled_bytes = 0; + for(uint8_t i; i= (current_time-10)) + { + sampled_bytes += meter_samples[meter_index].sample[i].byte_count; + } + } + + calculated_rate = ((sampled_bytes*8)/10); // bit/ms == kbit/s + TRACE("of_helper.c: calculated rate - %d kbps", calculated_rate); } else if(((meter_entry[meter_index]->flags) & OFPMF13_PKTPS) == OFPMF13_PKTPS) { - calculated_rate = 1000/time_delta; + // Calculate pkt/s from samples taken over last 10 ms + uint16_t sampled_packets = 0; + for(uint8_t i; i= (current_time-10)) + { + sampled_packets += meter_samples[meter_index].sample[i].packet_count; + } + } + + calculated_rate = 100*sampled_packets; // packets / 10 ms == 100 * packets over 10 ms TRACE("of_helper.c: calculated rate - %d pktps", calculated_rate); } else @@ -1362,9 +1413,6 @@ int meter_handler(uint32_t id, uint16_t bytes) { TRACE("of_helper.c: no bands triggered - packet not dropped"); - // Update timer - meter_entry[meter_index]->last_packet_in = sys_get_ms(); - return METER_NOACT; } diff --git a/ZodiacFX/src/openflow/openflow.h b/ZodiacFX/src/openflow/openflow.h index 4c9eb18..6db2c0a 100644 --- a/ZodiacFX/src/openflow/openflow.h +++ b/ZodiacFX/src/openflow/openflow.h @@ -100,6 +100,18 @@ struct meter_band_stats_array struct ofp13_meter_band_stats band_stats[MAX_METER_BANDS_13]; }; +struct policing_sample +{ + uint32_t packet_time; // sys_get_ms() when sampled + uint16_t byte_count; // Number of bytes during this sample + uint16_t packet_count; // Number of packets during this sample +}; + +struct meter_sample_array +{ + struct policing_sample sample[POLICING_SAMPLES]; +}; + void task_openflow(void); void nnOF_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port); void nnOF10_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port); From 534b115fe1d88969c3e7388d3fe9772e3fd6c659 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Sun, 23 Jul 2017 21:42:15 +1000 Subject: [PATCH 06/11] Fix metering sampling method --- ZodiacFX/src/config/config_zodiac.h | 1 + ZodiacFX/src/openflow/of_helper.c | 102 +++++++++++++++++----------- 2 files changed, 62 insertions(+), 41 deletions(-) diff --git a/ZodiacFX/src/config/config_zodiac.h b/ZodiacFX/src/config/config_zodiac.h index 9844d1e..06dfd4f 100644 --- a/ZodiacFX/src/config/config_zodiac.h +++ b/ZodiacFX/src/config/config_zodiac.h @@ -53,5 +53,6 @@ #define MAX_METER_13 8 // Maximum number of meter entries in meter table #define MAX_METER_BANDS_13 3 // Maximum number of meter bands per meter #define POLICING_SAMPLES 12 // Sample for rate limiter +#define POLICING_SLICE 10 // ms time slice for each sample #endif /* CONFIG_ZODIAC_H_ */ diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index f57091d..52d028c 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1323,62 +1323,56 @@ int meter_handler(uint32_t id, uint16_t bytes) // Get current time uint32_t current_time = (uint32_t)(sys_get_ms()); - // Check if last packet was within 1 ms of this one - if(meter_samples[meter_index].sample[sample_index].packet_time == current_time) - { - meter_samples[meter_index].sample[sample_index].byte_count += bytes; - meter_samples[meter_index].sample[sample_index].packet_count++; - } - else - { - // Increment sample index - if(sample_index >= 11) - { - // Wrap sample_index around - sample_index = 0; - } - else - { - // Increment index - sample_index++; - } - - // Populate (overwrite) next element - meter_samples[meter_index].sample[sample_index].packet_time = current_time; - meter_samples[meter_index].sample[sample_index].byte_count += bytes; - meter_samples[meter_index].sample[sample_index].packet_count++; - } - // Check configuration flags uint32_t calculated_rate = 0; if(((meter_entry[meter_index]->flags) & OFPMF13_KBPS) == OFPMF13_KBPS) { - // Calculate kbit/s from samples taken over last 10 ms + // Sum sampled bytes uint32_t sampled_bytes = 0; - for(uint8_t i; i= (current_time-10)) - { - sampled_bytes += meter_samples[meter_index].sample[i].byte_count; - } + sampled_bytes += meter_samples[meter_index].sample[i].byte_count; + } + + // Find time delta + uint32_t sample_time = 0; + if(sample_index == POLICING_SAMPLES-1) + { + //sample_time = meter_samples[meter_index].sample[sample_index].packet_time - meter_samples[meter_index].sample[0].packet_time; + sample_time = current_time - meter_samples[meter_index].sample[0].packet_time; + } + else + { + //sample_time = meter_samples[meter_index].sample[sample_index].packet_time - meter_samples[meter_index].sample[sample_index+1].packet_time; + sample_time = current_time - meter_samples[meter_index].sample[sample_index+1].packet_time; } - calculated_rate = ((sampled_bytes*8)/10); // bit/ms == kbit/s - TRACE("of_helper.c: calculated rate - %d kbps", calculated_rate); + calculated_rate = ((sampled_bytes*8)/sample_time); // bit/ms == kbit/s + TRACE("of_helper.c: calculated rate - %d kbps (%d bytes over %d ms)", calculated_rate, sampled_bytes, sample_time); } else if(((meter_entry[meter_index]->flags) & OFPMF13_PKTPS) == OFPMF13_PKTPS) { - // Calculate pkt/s from samples taken over last 10 ms + // Sum sampled packets uint16_t sampled_packets = 0; - for(uint8_t i; i= (current_time-10)) - { - sampled_packets += meter_samples[meter_index].sample[i].packet_count; - } + sampled_packets += meter_samples[meter_index].sample[i].packet_count; + } + + // Find time delta + uint32_t sample_time = 0; + if(sample_index == POLICING_SAMPLES-1) + { + //sample_time = meter_samples[meter_index].sample[sample_index].packet_time - meter_samples[meter_index].sample[0].packet_time; + sample_time = current_time - meter_samples[meter_index].sample[0].packet_time; + } + else + { + //sample_time = meter_samples[meter_index].sample[sample_index].packet_time - meter_samples[meter_index].sample[sample_index+1].packet_time; + sample_time = current_time - meter_samples[meter_index].sample[sample_index+1].packet_time; } - calculated_rate = 100*sampled_packets; // packets / 10 ms == 100 * packets over 10 ms + calculated_rate = 1000*sampled_packets; // 1000*pkt/ms == pkt/s TRACE("of_helper.c: calculated rate - %d pktps", calculated_rate); } else @@ -1413,6 +1407,32 @@ int meter_handler(uint32_t id, uint16_t bytes) { TRACE("of_helper.c: no bands triggered - packet not dropped"); + // Check if last packet was within 1 ms of this one + if(meter_samples[meter_index].sample[sample_index].packet_time == current_time) + { + meter_samples[meter_index].sample[sample_index].byte_count += bytes; + meter_samples[meter_index].sample[sample_index].packet_count++; + } + else + { + // Increment sample index + if(sample_index >= POLICING_SAMPLES-1) + { + // Wrap sample_index around + sample_index = 0; + } + else + { + // Increment index + sample_index++; + } + + // Populate (overwrite) next element + meter_samples[meter_index].sample[sample_index].packet_time = current_time; + meter_samples[meter_index].sample[sample_index].byte_count = bytes; + meter_samples[meter_index].sample[sample_index].packet_count++; + } + return METER_NOACT; } From 9bec538552489065c20899978756ece41db7d32b Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 24 Jul 2017 01:07:10 +1000 Subject: [PATCH 07/11] Modify sample rates --- ZodiacFX/src/config/config_zodiac.h | 4 ++-- ZodiacFX/src/openflow/of_helper.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ZodiacFX/src/config/config_zodiac.h b/ZodiacFX/src/config/config_zodiac.h index 06dfd4f..4184988 100644 --- a/ZodiacFX/src/config/config_zodiac.h +++ b/ZodiacFX/src/config/config_zodiac.h @@ -52,7 +52,7 @@ #define MAX_METER_13 8 // Maximum number of meter entries in meter table #define MAX_METER_BANDS_13 3 // Maximum number of meter bands per meter -#define POLICING_SAMPLES 12 // Sample for rate limiter -#define POLICING_SLICE 10 // ms time slice for each sample +#define POLICING_SAMPLES 4 // Sample for rate limiter +#define POLICING_SLICE 30 // time (ms) slice for each sample #endif /* CONFIG_ZODIAC_H_ */ diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 52d028c..6e41771 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1407,8 +1407,8 @@ int meter_handler(uint32_t id, uint16_t bytes) { TRACE("of_helper.c: no bands triggered - packet not dropped"); - // Check if last packet was within 1 ms of this one - if(meter_samples[meter_index].sample[sample_index].packet_time == current_time) + // Check if last packet was within 1 slice of this one + if(meter_samples[meter_index].sample[sample_index].packet_time >= (current_time-POLICING_SLICE-1)) { meter_samples[meter_index].sample[sample_index].byte_count += bytes; meter_samples[meter_index].sample[sample_index].packet_count++; @@ -1430,7 +1430,7 @@ int meter_handler(uint32_t id, uint16_t bytes) // Populate (overwrite) next element meter_samples[meter_index].sample[sample_index].packet_time = current_time; meter_samples[meter_index].sample[sample_index].byte_count = bytes; - meter_samples[meter_index].sample[sample_index].packet_count++; + meter_samples[meter_index].sample[sample_index].packet_count = 0; } return METER_NOACT; From 8c79652bc534a16ad0405696a52129d374b73a96 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 24 Jul 2017 12:49:12 +1000 Subject: [PATCH 08/11] Finalise sampling rates --- ZodiacFX/src/config/config_zodiac.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/config/config_zodiac.h b/ZodiacFX/src/config/config_zodiac.h index 4184988..8cc8cc7 100644 --- a/ZodiacFX/src/config/config_zodiac.h +++ b/ZodiacFX/src/config/config_zodiac.h @@ -52,7 +52,7 @@ #define MAX_METER_13 8 // Maximum number of meter entries in meter table #define MAX_METER_BANDS_13 3 // Maximum number of meter bands per meter -#define POLICING_SAMPLES 4 // Sample for rate limiter -#define POLICING_SLICE 30 // time (ms) slice for each sample +#define POLICING_SAMPLES 20 // Sample for rate limiter +#define POLICING_SLICE 1 // time (ms) slice for each sample #endif /* CONFIG_ZODIAC_H_ */ From f035983381209bf1a980607841381dd29937deec Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 24 Jul 2017 13:06:58 +1000 Subject: [PATCH 09/11] Fix pktps calculation --- ZodiacFX/src/config/config_zodiac.h | 2 +- ZodiacFX/src/openflow/of_helper.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ZodiacFX/src/config/config_zodiac.h b/ZodiacFX/src/config/config_zodiac.h index 8cc8cc7..d24b34d 100644 --- a/ZodiacFX/src/config/config_zodiac.h +++ b/ZodiacFX/src/config/config_zodiac.h @@ -53,6 +53,6 @@ #define MAX_METER_13 8 // Maximum number of meter entries in meter table #define MAX_METER_BANDS_13 3 // Maximum number of meter bands per meter #define POLICING_SAMPLES 20 // Sample for rate limiter -#define POLICING_SLICE 1 // time (ms) slice for each sample +#define POLICING_SLICE 2 // time (ms) slice for each sample #endif /* CONFIG_ZODIAC_H_ */ diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 6e41771..641b02f 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1372,8 +1372,8 @@ int meter_handler(uint32_t id, uint16_t bytes) sample_time = current_time - meter_samples[meter_index].sample[sample_index+1].packet_time; } - calculated_rate = 1000*sampled_packets; // 1000*pkt/ms == pkt/s - TRACE("of_helper.c: calculated rate - %d pktps", calculated_rate); + calculated_rate = 1000*sampled_packets/sample_time; // 1000*pkt/ms == pkt/s + TRACE("of_helper.c: calculated rate - %d pktps (%d packets over %d ms)", calculated_rate, sampled_packets, sample_time); } else { From 70e58338d8312f9ca52be014638e5a905a14174e Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 24 Jul 2017 13:35:23 +1000 Subject: [PATCH 10/11] Fix multiple meter sampling indexes --- ZodiacFX/src/openflow/of_helper.c | 28 ++++++++++++++-------------- ZodiacFX/src/openflow/openflow.h | 3 ++- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 641b02f..3ac3f4c 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1282,7 +1282,7 @@ int meter_handler(uint32_t id, uint16_t bytes) { // Initialise 8x 12-element packet samples static struct meter_sample_array meter_samples[MAX_METER_13]; - static uint8_t sample_index = 0; + //static uint16_t sample_index = 0; TRACE("of_helper.c: meter id %d needs processing", id); @@ -1336,7 +1336,7 @@ int meter_handler(uint32_t id, uint16_t bytes) // Find time delta uint32_t sample_time = 0; - if(sample_index == POLICING_SAMPLES-1) + if(meter_samples[meter_index].sample_index == POLICING_SAMPLES-1) { //sample_time = meter_samples[meter_index].sample[sample_index].packet_time - meter_samples[meter_index].sample[0].packet_time; sample_time = current_time - meter_samples[meter_index].sample[0].packet_time; @@ -1344,7 +1344,7 @@ int meter_handler(uint32_t id, uint16_t bytes) else { //sample_time = meter_samples[meter_index].sample[sample_index].packet_time - meter_samples[meter_index].sample[sample_index+1].packet_time; - sample_time = current_time - meter_samples[meter_index].sample[sample_index+1].packet_time; + sample_time = current_time - meter_samples[meter_index].sample[meter_samples[meter_index].sample_index+1].packet_time; } calculated_rate = ((sampled_bytes*8)/sample_time); // bit/ms == kbit/s @@ -1361,7 +1361,7 @@ int meter_handler(uint32_t id, uint16_t bytes) // Find time delta uint32_t sample_time = 0; - if(sample_index == POLICING_SAMPLES-1) + if(meter_samples[meter_index].sample_index == POLICING_SAMPLES-1) { //sample_time = meter_samples[meter_index].sample[sample_index].packet_time - meter_samples[meter_index].sample[0].packet_time; sample_time = current_time - meter_samples[meter_index].sample[0].packet_time; @@ -1369,7 +1369,7 @@ int meter_handler(uint32_t id, uint16_t bytes) else { //sample_time = meter_samples[meter_index].sample[sample_index].packet_time - meter_samples[meter_index].sample[sample_index+1].packet_time; - sample_time = current_time - meter_samples[meter_index].sample[sample_index+1].packet_time; + sample_time = current_time - meter_samples[meter_index].sample[meter_samples[meter_index].sample_index+1].packet_time; } calculated_rate = 1000*sampled_packets/sample_time; // 1000*pkt/ms == pkt/s @@ -1408,29 +1408,29 @@ int meter_handler(uint32_t id, uint16_t bytes) TRACE("of_helper.c: no bands triggered - packet not dropped"); // Check if last packet was within 1 slice of this one - if(meter_samples[meter_index].sample[sample_index].packet_time >= (current_time-POLICING_SLICE-1)) + if(meter_samples[meter_index].sample[meter_samples[meter_index].sample_index].packet_time >= (current_time-POLICING_SLICE-1)) { - meter_samples[meter_index].sample[sample_index].byte_count += bytes; - meter_samples[meter_index].sample[sample_index].packet_count++; + meter_samples[meter_index].sample[meter_samples[meter_index].sample_index].byte_count += bytes; + meter_samples[meter_index].sample[meter_samples[meter_index].sample_index].packet_count++; } else { // Increment sample index - if(sample_index >= POLICING_SAMPLES-1) + if(meter_samples[meter_index].sample_index >= POLICING_SAMPLES-1) { // Wrap sample_index around - sample_index = 0; + meter_samples[meter_index].sample_index = 0; } else { // Increment index - sample_index++; + meter_samples[meter_index].sample_index++; } // Populate (overwrite) next element - meter_samples[meter_index].sample[sample_index].packet_time = current_time; - meter_samples[meter_index].sample[sample_index].byte_count = bytes; - meter_samples[meter_index].sample[sample_index].packet_count = 0; + meter_samples[meter_index].sample[meter_samples[meter_index].sample_index].packet_time = current_time; + meter_samples[meter_index].sample[meter_samples[meter_index].sample_index].byte_count = bytes; + meter_samples[meter_index].sample[meter_samples[meter_index].sample_index].packet_count = 0; } return METER_NOACT; diff --git a/ZodiacFX/src/openflow/openflow.h b/ZodiacFX/src/openflow/openflow.h index 6db2c0a..3e58f32 100644 --- a/ZodiacFX/src/openflow/openflow.h +++ b/ZodiacFX/src/openflow/openflow.h @@ -109,7 +109,8 @@ struct policing_sample struct meter_sample_array { - struct policing_sample sample[POLICING_SAMPLES]; + uint16_t sample_index; + struct policing_sample sample[POLICING_SAMPLES]; }; void task_openflow(void); From 411e3992f912d7db4847fd78873be14179bb3765 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Mon, 24 Jul 2017 15:22:27 +1000 Subject: [PATCH 11/11] Update README.md Clarify curl command usage --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 78459f7..3ea1489 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ Download the latest **update firmware** from the [Northbound Networks Forums](ht * Click 'Restart' in the web interface header to complete the update * **[Advanced] To update via cURL**: - * Run the following command: **curl --verbose -0 --form "file=@ZodiacFX_vXX_update.bin"** - * If the firmware upload fails, you may need to use the multipart/related content type like so: **curl -H "Content-Type: multipart/related" --verbose -0 --form "file=@ZodiacFX_vXX_update.bin"** + * Run the following command: **curl --verbose -0 --form "file=@ZodiacFX_vXX_update.bin" *ip_address*** + * If the firmware upload fails, you may need to use the multipart/related content type like so: **curl -H "Content-Type: multipart/related" --verbose -0 --form "file=@ZodiacFX_vXX_update.bin" *ip_address*** * Note: a restart is required after the update to load the new firmware. ## Building the Project