Skip to content

Commit

Permalink
Merge pull request #83 from pzanna/Dev_82
Browse files Browse the repository at this point in the history
Dev 82
  • Loading branch information
pzanna authored Aug 1, 2017
2 parents 1773a53 + d8f58d1 commit f12d0c2
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion ZodiacFX/src/config/config_zodiac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -52,5 +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 20 // Sample for rate limiter
#define POLICING_SLICE 2 // time (ms) slice for each sample

#endif /* CONFIG_ZODIAC_H_ */
116 changes: 95 additions & 21 deletions ZodiacFX/src/openflow/of_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -1274,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 uint16_t sample_index = 0;

TRACE("of_helper.c: meter id %d needs processing", id);

// Get associated meter entry
Expand All @@ -1299,34 +1308,72 @@ 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;
}

// Find time delta
uint64_t time_delta = sys_get_ms() - meter_entry[meter_index]->last_packet_in;
//// 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;
//}

// Update timer
meter_entry[meter_index]->last_packet_in = sys_get_ms();
// Get current time
uint32_t current_time = (uint32_t)(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);
// Sum sampled bytes
uint32_t sampled_bytes = 0;
for(uint16_t i; i<POLICING_SAMPLES; i++)
{
sampled_bytes += meter_samples[meter_index].sample[i].byte_count;
}

// Find time delta
uint32_t sample_time = 0;
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;
}
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[meter_samples[meter_index].sample_index+1].packet_time;
}

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)
{
calculated_rate = 1000/time_delta;
TRACE("of_helper.c: calculated rate - %d pktps", calculated_rate);
// Sum sampled packets
uint16_t sampled_packets = 0;
for(uint16_t i; i<POLICING_SAMPLES; i++)
{
sampled_packets += meter_samples[meter_index].sample[i].packet_count;
}

// Find time delta
uint32_t sample_time = 0;
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;
}
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[meter_samples[meter_index].sample_index+1].packet_time;
}

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
{
Expand Down Expand Up @@ -1359,6 +1406,33 @@ 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");

// Check if last packet was within 1 slice of this one
if(meter_samples[meter_index].sample[meter_samples[meter_index].sample_index].packet_time >= (current_time-POLICING_SLICE-1))
{
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(meter_samples[meter_index].sample_index >= POLICING_SAMPLES-1)
{
// Wrap sample_index around
meter_samples[meter_index].sample_index = 0;
}
else
{
// Increment index
meter_samples[meter_index].sample_index++;
}

// Populate (overwrite) next element
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;
}

Expand Down
13 changes: 13 additions & 0 deletions ZodiacFX/src/openflow/openflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ 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
{
uint16_t sample_index;
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);
Expand Down

0 comments on commit f12d0c2

Please sign in to comment.