Skip to content

Commit

Permalink
Merge pull request #93 from pzanna/Dev_85
Browse files Browse the repository at this point in the history
Dev 85
  • Loading branch information
pzanna authored Jun 26, 2019
2 parents 4b707d4 + 9bcfdea commit c7d8c3c
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 26 deletions.
25 changes: 25 additions & 0 deletions ZodiacFX/src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ void command_root(char *command, char *param1, char *param2, char *param3)

// Force OpenFlow version
reset_config.of_version = 0; // Force version disabled

//How often to retrieve stats from switch
reset_config.stats_interval = 1; // Default 1 second

memcpy(&reset_config.MAC_address, &Zodiac_Config.MAC_address, 6); // Copy over existing MAC address so it is not reset
memcpy(&Zodiac_Config, &reset_config, sizeof(struct zodiac_config));
Expand Down Expand Up @@ -485,6 +488,7 @@ void command_root(char *command, char *param1, char *param2, char *param3)
}
if (Zodiac_Config.ethtype_filter == 1) printf(" EtherType Filtering: Enabled\r\n");
if (Zodiac_Config.ethtype_filter != 1) printf(" EtherType Filtering: Disabled\r\n");
printf(" Port Stats Interval: %d\r\n" , Zodiac_Config.stats_interval);
printf("\r\n\n");
return;
}
Expand Down Expand Up @@ -589,6 +593,7 @@ void command_config(char *command, char *param1, char *param2, char *param3)
}
if (Zodiac_Config.ethtype_filter == 1) printf(" EtherType Filtering: Enabled\r\n");
if (Zodiac_Config.ethtype_filter != 1) printf(" EtherType Filtering: Disabled\r\n");
printf(" Port Stats Interval: %d\r\n" , Zodiac_Config.stats_interval);
printf("\r\n-------------------------------------------------------------------------\r\n\n");
return;
}
Expand Down Expand Up @@ -942,6 +947,9 @@ void command_config(char *command, char *param1, char *param2, char *param3)
// Force OpenFlow version
reset_config.of_version = 0; // Force version disabled

//How often to retrieve stats from switch
reset_config.stats_interval = 1; // Default 1 second

memcpy(&reset_config.MAC_address, &Zodiac_Config.MAC_address, 6); // Copy over existng MAC address so it is not reset
memcpy(&Zodiac_Config, &reset_config, sizeof(struct zodiac_config));
saveConfig();
Expand Down Expand Up @@ -998,7 +1006,23 @@ void command_config(char *command, char *param1, char *param2, char *param3)
}
return;
}

// Set port stats update interval
if (strcmp(command, "set")==0 && strcmp(param1, "stats-interval")==0)
{
int interval;
sscanf(param2, "%d", &interval);
if (interval < 31 && interval > -1)
{
Zodiac_Config.stats_interval = interval;
printf("Port stats interval set to %d\r\n" , Zodiac_Config.stats_interval);
} else {
printf("Invalid value\r\n");
}
return;
}


// Unknown Command
printf("Unknown command\r\n");
return;
Expand Down Expand Up @@ -1934,6 +1958,7 @@ void printhelp(void)
printf(" delete vlan-port <port>\r\n");
printf(" set of-version <version(0|1|4)>\r\n");
printf(" set ethertype-filter <enable|disable>\r\n");
printf(" set stats-interval <seconds>\r\n");
printf(" factory reset\r\n");
printf(" exit\r\n");
printf("\r\n");
Expand Down
1 change: 1 addition & 0 deletions ZodiacFX/src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct zodiac_config {
uint8_t failstate;
uint8_t of_version;
uint8_t ethtype_filter;
uint8_t stats_interval;
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END

Expand Down
3 changes: 1 addition & 2 deletions 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.84" // Firmware version number
#define VERSION "0.85" // Firmware version number

#define TOTAL_PORTS 4 // Total number of physical ports on the Zodiac FX

Expand All @@ -48,7 +48,6 @@
#define MAX_BUCKETS 4 // Maximum number of group action buckets for OpenFlow 1.3 and higher

#define HB_INTERVAL 2 // Number of seconds between heartbeats

#define HB_TIMEOUT 6 // Number of seconds to wait when there is no response from the controller

#define MAX_OF_STATS 15 // Maximum number of flows to send to controller
Expand Down
3 changes: 3 additions & 0 deletions ZodiacFX/src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,9 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err

// Force OpenFlow version
reset_config.of_version = 0; // Force version disabled

//How often to retrieve stats from switch
reset_config.stats_interval = 1; // Default 1 second

memcpy(&reset_config.MAC_address, &Zodiac_Config.MAC_address, 6); // Copy over existing MAC address so it is not reset
memcpy(&Zodiac_Config, &reset_config, sizeof(struct zodiac_config));
Expand Down
1 change: 1 addition & 0 deletions ZodiacFX/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ int main (void)
membag_init();

loadConfig(); // Load Config
if (Zodiac_Config.stats_interval > 30) Zodiac_Config.stats_interval = 1; // If this value has never been set make it the default of 1

IP4_ADDR(&x_ip_addr, Zodiac_Config.IP_address[0], Zodiac_Config.IP_address[1],Zodiac_Config.IP_address[2], Zodiac_Config.IP_address[3]);
IP4_ADDR(&x_net_mask, Zodiac_Config.netmask[0], Zodiac_Config.netmask[1],Zodiac_Config.netmask[2], Zodiac_Config.netmask[3]);
Expand Down
34 changes: 19 additions & 15 deletions ZodiacFX/src/openflow/of_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ extern uint8_t *ofp13_oxm_inst[MAX_FLOWS_13];
extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13];

// Local Variables
uint8_t timer_alt;
uint8_t timer_alt = 0;
uint8_t update_interval = 0;
static uint16_t VLAN_VID_MASK = 0x0fff;

static inline uint64_t (htonll)(uint64_t n)
Expand Down Expand Up @@ -139,21 +140,24 @@ void nnOF_timer(void)
{
totaltime ++; // Because this is called every 500ms totaltime is actually 2 x the real time
// Round robin the timer events so they don't have such a big impact on switching
if (timer_alt == 0){
update_port_stats();
timer_alt = 1;
} else if (timer_alt == 1){
update_port_status();
// If port status has changed send a port status message
for (int x=0;x<TOTAL_PORTS;x++)
{
if (last_port_status[x] != port_status[x] && OF_Version == 1 && Zodiac_Config.of_port[x] == 1) port_status_message10(x);
if (last_port_status[x] != port_status[x] && OF_Version == 4 && Zodiac_Config.of_port[x] == 1) port_status_message13(x);
update_interval ++;
if ((update_interval/2) > Zodiac_Config.stats_interval)
{
if (timer_alt == 0){
if (Zodiac_Config.stats_interval > 0) update_port_stats();
timer_alt = 1;
} else if (timer_alt == 1){
flow_timeouts();
if (Zodiac_Config.stats_interval > 0) update_port_status();
// If port status has changed send a port status message
for (int x=0;x<TOTAL_PORTS;x++)
{
if (last_port_status[x] != port_status[x] && OF_Version == 1 && Zodiac_Config.of_port[x] == 1) port_status_message10(x);
if (last_port_status[x] != port_status[x] && OF_Version == 4 && Zodiac_Config.of_port[x] == 1) port_status_message13(x);
}
timer_alt = 0;
}
timer_alt = 2;
} else if (timer_alt == 2){
flow_timeouts();
timer_alt = 0;
update_interval = 2;
}
return;
}
Expand Down
15 changes: 6 additions & 9 deletions ZodiacFX/src/openflow/openflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool rcv_freq;
// Internal Functions
void OF_hello(void);
void echo_request(void);
void echo_reply(uint32_t xid);
void echo_reply(struct ofp_header *ofph, int size, int len);
err_t TCPready(void *arg, struct tcp_pcb *tpcb, err_t err);
void tcp_error(void * arg, err_t err);
static err_t of_receive(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
Expand Down Expand Up @@ -190,7 +190,7 @@ static err_t of_receive(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t e
break;

case OFPT10_ECHO_REQUEST:
echo_reply(ofph->xid);
echo_reply(ofph, size, len);
break;

default:
Expand Down Expand Up @@ -259,15 +259,12 @@ void OF_hello(void)
* @param xid - transaction ID
*
*/
void echo_reply(uint32_t xid)
void echo_reply(struct ofp_header *ofph, int size, int len)
{
struct ofp_header echo;
echo.version = OF_Version;
echo.length = HTONS(sizeof(echo));
echo.type = OFPT10_ECHO_REPLY;
echo.xid = xid;
// Change the message type to Echo Reply and return any data that was sent
ofph->type = OFPT10_ECHO_REPLY;
TRACE("openflow.c: Sent ECHO reply");
sendtcp(&echo, sizeof(echo), 1);
sendtcp(ofph, len, 1);
return;
}

Expand Down

0 comments on commit c7d8c3c

Please sign in to comment.