Skip to content

Commit

Permalink
Merge pull request #90 from pzanna/Dev_84
Browse files Browse the repository at this point in the history
Dev 84
  • Loading branch information
pzanna authored Apr 14, 2018
2 parents 95f25d6 + 8cc3442 commit 4b707d4
Show file tree
Hide file tree
Showing 9 changed files with 725 additions and 73 deletions.
109 changes: 103 additions & 6 deletions ZodiacFX/src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ extern bool debug_output;
extern int charcount, charcount_last;
extern struct ofp_flow_mod *flow_match10[MAX_FLOWS_10];
extern struct ofp13_flow_mod *flow_match13[MAX_FLOWS_13];
extern struct group_entry13 group_entry13[MAX_GROUPS];
extern struct action_bucket action_bucket[MAX_BUCKETS];
extern uint8_t *ofp13_oxm_match[MAX_FLOWS_13];
extern uint8_t *ofp13_oxm_inst[MAX_FLOWS_13];
extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13];
Expand Down Expand Up @@ -594,19 +596,21 @@ void command_config(char *command, char *param1, char *param2, char *param3)
// Display VLANs
if (strcmp(command, "show")==0 && strcmp(param1, "vlans")==0){
int x;
printf("\r\n\tVLAN ID\t\tName\t\t\tType\r\n");
printf("-------------------------------------------------------------------------\r\n");
printf("\r\n\tVLAN ID\t\tName\t\t\tType\t\tTag\r\n");
printf("-------------------------------------------------------------------------------\r\n");
for (x=0;x<MAX_VLANS;x++)
{
if (Zodiac_Config.vlan_list[x].uActive == 1)
{
printf("\t%d\t\t'%s'\t\t",Zodiac_Config.vlan_list[x].uVlanID, Zodiac_Config.vlan_list[x].cVlanName);
if (Zodiac_Config.vlan_list[x].uVlanType == 0) printf("Undefined\r\n");
if (Zodiac_Config.vlan_list[x].uVlanType == 1) printf("OpenFlow\r\n");
if (Zodiac_Config.vlan_list[x].uVlanType == 2) printf("Native\r\n");
if (Zodiac_Config.vlan_list[x].uVlanType == 0) printf("Undefined\t");
if (Zodiac_Config.vlan_list[x].uVlanType == 1) printf("OpenFlow\t");
if (Zodiac_Config.vlan_list[x].uVlanType == 2) printf("Native\t\t");
if (Zodiac_Config.vlan_list[x].uTagged == 0) printf("Untagged\r\n");
if (Zodiac_Config.vlan_list[x].uTagged == 1) printf("Tagged\r\n");
}
}
printf("\r\n-------------------------------------------------------------------------\r\n\n");
printf("\r\n-------------------------------------------------------------------------------\r\n\n");
return;
}

Expand Down Expand Up @@ -686,6 +690,33 @@ void command_config(char *command, char *param1, char *param2, char *param3)
return;
}

// Set VLAN tagging
if (strcmp(command, "set")==0 && strcmp(param1, "vlan-tag")==0)
{
int vlanid;
sscanf(param2, "%d", &vlanid);
for (int x=0;x<MAX_VLANS;x++)
{
if(Zodiac_Config.vlan_list[x].uVlanID == vlanid)
{
if(strcmp(param3, "untagged")==0){
Zodiac_Config.vlan_list[x].uTagged = 0;
printf("VLAN %d set to untagged\r\n",vlanid);
return;
}
if(strcmp(param3, "tagged")==0){
Zodiac_Config.vlan_list[x].uTagged = 1;
printf("VLAN %d set to tagged\r\n",vlanid);
return;
}
printf("Unknown VLAN tag setting\r\n");
return;
}
}
printf("Unknown VLAN ID\r\n");
return;
}

// Add port to VLAN
if (strcmp(command, "add")==0 && strcmp(param1, "vlan-port")==0)
{
Expand Down Expand Up @@ -1479,6 +1510,11 @@ void command_openflow(char *command, char *param1, char *param2, char *param3)
printf(" Pop MPLS tag\r\n");
}

if (htons(act_hdr->type) == OFPAT13_GROUP)
{
struct ofp13_action_group *act_group = act_hdr;
printf(" Apply Group: %d\r\n", htonl(act_group->group_id));
}
act_size += htons(act_hdr->len);
}
}
Expand Down Expand Up @@ -1716,6 +1752,65 @@ void command_openflow(char *command, char *param1, char *param2, char *param3)
}
return;
}

// Show meter table entries
if (strcmp(command, "show") == 0 && strcmp(param1, "groups") == 0)
{
int g;
bool no_groups = true;

// Find first empty group entry
for(g=0;g<MAX_GROUPS;g++)
{
if (group_entry13[g].active == true)
{
no_groups = false;
printf("\r\nGroup ID %d\r\n", g+1);
if (group_entry13[g].type == OFPGT13_ALL) printf(" Type: ALL\r\n");
if (group_entry13[g].type == OFPGT13_SELECT) printf(" Type: SELECT\r\n");
if (group_entry13[g].type == OFPGT13_INDIRECT) printf(" Type: INDIRECT\r\n");
if (group_entry13[g].type == OFPGT13_FF) printf(" Type: FAST FAILOVER\r\n");
printf(" Actions:\r\n");

struct ofp13_bucket *bucket_hdr;
bucket_hdr = (struct ofp13_bucket *)action_bucket[group_entry13[g].bucket_id-1].data;
struct ofp13_action_header *act_hdr;
uint8_t act_size = sizeof(struct ofp13_bucket);
if (htons(bucket_hdr->len == sizeof(struct ofp13_bucket))) printf(" DROP \r\n"); // No actions

while (act_size < htons(bucket_hdr->len))
{
act_hdr = (struct ofp13_action_header*)((uintptr_t)bucket_hdr + act_size);
if (htons(act_hdr->type) == OFPAT13_OUTPUT)
{
struct ofp13_action_output *act_output = act_hdr;
if (htonl(act_output->port) < OFPP13_MAX)
{
printf(" Output Port: %d\r\n", htonl(act_output->port));
} else if (htonl(act_output->port) == OFPP13_IN_PORT)
{
printf(" Output: IN_PORT \r\n");
} else if (htonl(act_output->port) == OFPP13_FLOOD)
{
printf(" Output: FLOOD \r\n");
} else if (htonl(act_output->port) == OFPP13_ALL)
{
printf(" Output: ALL \r\n");
} else if (htonl(act_output->port) == OFPP13_CONTROLLER)
{
printf(" Output: CONTROLLER \r\n");
} else if (htonl(act_output->port) == OFPP13_NORMAL)
{
printf(" Output: NORMAL \r\n");
}
}
act_size += htons(act_hdr->len);
}
}
}
if (no_groups == true) printf("No groups configured.\r\n");
return;
}
// Unknown Command
printf("Unknown command\r\n");
return;
Expand Down Expand Up @@ -1834,6 +1929,7 @@ void printhelp(void)
printf(" add vlan <vlan id> <vlan name>\r\n");
printf(" delete vlan <vlan id>\r\n");
printf(" set vlan-type <vlan id> <openflow|native>\r\n");
printf(" set vlan-tag <vlan id> <tagged|untagged>\r\n");
printf(" add vlan-port <vlan id> <port>\r\n");
printf(" delete vlan-port <port>\r\n");
printf(" set of-version <version(0|1|4)>\r\n");
Expand All @@ -1846,6 +1942,7 @@ void printhelp(void)
printf(" show tables\r\n");
printf(" show flows\r\n");
printf(" show meters\r\n");
printf(" show groups\r\n");
printf(" enable\r\n");
printf(" disable\r\n");
printf(" clear flows\r\n");
Expand Down
5 changes: 4 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.83" // Firmware version number
#define VERSION "0.84" // Firmware version number

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

Expand All @@ -44,6 +44,9 @@

#define MAX_TABLES 10 // Maximum number of tables for OpenFlow 1.3 and higher

#define MAX_GROUPS 4 // Maximum number of groups for OpenFlow 1.3 and higher
#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
Expand Down
22 changes: 15 additions & 7 deletions ZodiacFX/src/openflow/of_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ extern struct flows_counter flow_counters[MAX_FLOWS_13];
extern struct table_counter table_counters[MAX_TABLES];
extern struct meter_entry13 *meter_entry[MAX_METER_13];
extern struct meter_band_stats_array band_stats_array[MAX_METER_13];
extern struct group_entry13 group_entry13[MAX_GROUPS];
extern struct action_bucket action_bucket[MAX_BUCKETS];
extern struct ofp_flow_mod *flow_match10[MAX_FLOWS_10];
extern struct flow_tbl_actions *flow_actions10[MAX_FLOWS_10];
extern struct ofp13_flow_mod *flow_match13[MAX_FLOWS_13];
Expand Down Expand Up @@ -407,7 +409,7 @@ int flowmatch13(uint8_t *pBuffer, int port, uint8_t table_id, struct packet_fiel
case OXM_OF_ETH_DST_W:
for (int j=0; j<6; j++ )
{
if (oxm_value[j] != eth_dst[j] & oxm_value[6+j]){
if ((oxm_value[j] & oxm_value[6+j]) != eth_dst[j] & oxm_value[6+j]){
priority_match = -1;
}
}
Expand All @@ -423,7 +425,7 @@ int flowmatch13(uint8_t *pBuffer, int port, uint8_t table_id, struct packet_fiel
case OXM_OF_ETH_SRC_W:
for (int j=0; j<6; j++ )
{
if (oxm_value[j] != eth_src[j] & oxm_value[6+j]){
if ((oxm_value[j] & oxm_value[6+j]) != eth_src[j] & oxm_value[6+j]){
priority_match = -1;
}
}
Expand Down Expand Up @@ -570,13 +572,9 @@ int flowmatch13(uint8_t *pBuffer, int port, uint8_t table_id, struct packet_fiel
priority_match = -1;
}
break;
if (!(fields->isVlanTag && (pBuffer[14]>>5) == oxm_value[0]))
{
priority_match = -1;
}

case OXM_OF_MPLS_LABEL:
if (fields->isMPLSTag && fields->mpls_label != ntohl(*(uint32_t*)oxm_value))
if (fields->isMPLSTag && fields->mpls_label != *(uint32_t*)oxm_value)
{
priority_match = -1;
}
Expand All @@ -596,6 +594,9 @@ int flowmatch13(uint8_t *pBuffer, int port, uint8_t table_id, struct packet_fiel
}
break;

default:
priority_match = -1;
break;
}

if (priority_match == -1)
Expand Down Expand Up @@ -1198,6 +1199,13 @@ void clear_flows(void)
meter_entry[x] = NULL;
}
}

/* Clear Groups*/
for(int x=0; x<MAX_GROUPS;x++)
{
group_entry13[x].active = false;
action_bucket[group_entry13[x].bucket_id-1].active = false;
}
}

/*
Expand Down
23 changes: 17 additions & 6 deletions ZodiacFX/src/openflow/openflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ extern struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS];
struct ofp_switch_config Switch_config;
struct ofp_flow_mod *flow_match10[MAX_FLOWS_10];
struct ofp13_flow_mod *flow_match13[MAX_FLOWS_13];
struct group_entry13 group_entry13[MAX_GROUPS];
struct action_bucket action_bucket[MAX_BUCKETS];
uint8_t *ofp13_oxm_match[MAX_FLOWS_13];
uint8_t *ofp13_oxm_inst[MAX_FLOWS_13];
uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13];
Expand Down Expand Up @@ -247,7 +249,7 @@ void OF_hello(void)
ofph.length = HTONS(sizeof(ofph));
ofph.xid = HTONL(1);
TRACE("openflow.c: Sending HELLO, version 0x%d", ofph.version);
sendtcp(&ofph, sizeof(ofph));
sendtcp(&ofph, sizeof(ofph), 1);
return;
}

Expand All @@ -265,7 +267,7 @@ void echo_reply(uint32_t xid)
echo.type = OFPT10_ECHO_REPLY;
echo.xid = xid;
TRACE("openflow.c: Sent ECHO reply");
sendtcp(&echo, sizeof(echo));
sendtcp(&echo, sizeof(echo), 1);
return;
}

Expand All @@ -281,7 +283,7 @@ void echo_request(void)
echo.type = OFPT10_ECHO_REQUEST;
echo.xid = 1234;
TRACE("openflow.c: Sent ECHO request");
sendtcp(&echo, sizeof(echo));
sendtcp(&echo, sizeof(echo), 1);
return;
}

Expand All @@ -292,7 +294,7 @@ void echo_request(void)
* @param len - size of the packet to send
*
*/
void sendtcp(const void *buffer, u16_t len)
void sendtcp(const void *buffer, uint16_t len, uint8_t push)
{
err_t err;
uint16_t buf_size;
Expand All @@ -305,8 +307,17 @@ void sendtcp(const void *buffer, u16_t len)
}

buf_size = tcp_sndbuf(tcp_pcb);
err = tcp_write(tcp_pcb, buffer, len, TCP_WRITE_FLAG_COPY + TCP_WRITE_FLAG_MORE);
TRACE("openflow.c: Sending %d bytes to TCP stack, %d available in buffer", len, buf_size);
if (push == 0)
{
TRACE("openflow.c: Sending %d bytes to TCP stack, %d available in buffer", len, buf_size);
err = tcp_write(tcp_pcb, buffer, len, TCP_WRITE_FLAG_COPY + TCP_WRITE_FLAG_MORE);

} else {
TRACE("openflow.c: Sending %d bytes immediately, %d available in buffer", len, buf_size);
err = tcp_write(tcp_pcb, buffer, len, TCP_WRITE_FLAG_COPY);
tcp_output(tcp_pcb);
}

return;
}

Expand Down
19 changes: 18 additions & 1 deletion ZodiacFX/src/openflow/openflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ struct meter_sample_array
struct policing_sample sample[POLICING_SAMPLES];
};

struct group_entry13 {
int active;
uint8_t type;
uint8_t pad;
uint8_t bucket_id;
uint64_t packet_count;
uint64_t byte_count;
uint64_t time_added;
};

struct action_bucket {
int active;
uint64_t packet_count;
uint64_t byte_count;
uint8_t data[64];
};

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 All @@ -122,7 +139,7 @@ void of13_message(struct ofp_header *ofph, int size, int len);
void multi_flow_more_reply13(void);
void barrier10_reply(uint32_t xid);
void barrier13_reply(uint32_t xid);
void sendtcp(const void *buffer, u16_t len);
void sendtcp(const void *buffer, uint16_t len, uint8_t push);
void flowrem_notif10(int flowid, uint8_t reason);
void flowrem_notif13(int flowid, uint8_t reason);
void port_status_message10(uint8_t port);
Expand Down
Loading

0 comments on commit 4b707d4

Please sign in to comment.