From 04aaf88f01e49082f41e2a811c370138a1364307 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:21:46 +1000 Subject: [PATCH 01/23] Remove stacking source files --- ZodiacFX/src/command.c | 1 - ZodiacFX/src/main.c | 1 - ZodiacFX/src/openflow/openflow.c | 1 - ZodiacFX/src/stacking.c | 642 ------------------------------- ZodiacFX/src/stacking.h | 94 ----- ZodiacFX/src/switch.c | 1 - 6 files changed, 740 deletions(-) delete mode 100644 ZodiacFX/src/stacking.c delete mode 100644 ZodiacFX/src/stacking.h diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index b267f17..3afb6b8 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -38,7 +38,6 @@ #include "eeprom.h" #include "switch.h" #include "flash.h" -#include "stacking.h" #include "openflow/openflow.h" #include "openflow/of_helper.h" #include "lwip/def.h" diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index 07ffcb9..7b1e664 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -42,7 +42,6 @@ #include "command.h" #include "eeprom.h" #include "switch.h" -#include "stacking.h" #include "http.h" #include "flash.h" #include "openflow/openflow.h" diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 89d320c..c2aed17 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -39,7 +39,6 @@ #include "lwip/tcp.h" #include "lwip/err.h" #include "timers.h" -#include "stacking.h" // Global variables extern struct zodiac_config Zodiac_Config; diff --git a/ZodiacFX/src/stacking.c b/ZodiacFX/src/stacking.c deleted file mode 100644 index 6d4fb9f..0000000 --- a/ZodiacFX/src/stacking.c +++ /dev/null @@ -1,642 +0,0 @@ -/** - * @file - * stacking.c - * - * This file contains the stacking functions - * - */ - -/* - * This file is part of the Zodiac FX firmware. - * Copyright (c) 2017 Northbound Networks. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Authors: Paul Zanna - * & Kristopher Chen - * - */ - -#include -#include -#include "stacking.h" -#include "trace.h" -#include "switch.h" -#include "lwip/def.h" -#include "openflow/openflow.h" -#include "timers.h" - -/* SPI clock setting (Hz). */ -static uint32_t gs_ul_spi_clock = 10000000; - -/* Chip select. */ -#define SPI_CHIP_SEL 0 -#define SPI_CHIP_PCS spi_get_pcs(SPI_CHIP_SEL) -/* Clock polarity. */ -#define SPI_CLK_POLARITY 0 -/* Clock phase. */ -#define SPI_CLK_PHASE 0 -/* Delay before SPCK. */ -#define SPI_DLYBS 0x30 -/* Delay between consecutive transfers. */ -#define SPI_DLYBCT 0x06 - -// Global variables -extern uint8_t last_port_status[8]; -extern uint8_t port_status[8]; -extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; -extern uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; -extern int OF_Version; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern struct ofp13_port_stats phys13_port_stats[8]; - -// Local variables -uint16_t spi_slave_send_size; -int32_t spi_slave_send_count; -uint8_t timer_alt; -uint8_t pending_spi_command = SPI_SEND_READY; -bool master_ready; -bool slave_ready; -uint8_t spi_dummy_bytes = 0; -struct spi_port_stats spi_p_stats; -uint8_t spi_stats_rr = 0; -struct spi_packet *spi_packet; -bool end_check; -uint8_t spi_receive_port = 0; -uint16_t spi_receive_count; -uint32_t rcv_time; - -void spi_master_initialize(void); -void spi_slave_initialize(void); -void spi_port_stats(void); -void spi_port_status(void); - -struct spi_debug_stats spi_debug; - -/* -* Initialize the SPI interface to MASTER or SLAVE based on the stacking jumper -* -*/ -void stacking_init(bool master) -{ - if (master) - { - spi_slave_initialize(); - ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_OUTPUT); - } else { - spi_master_initialize(); - ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_INPUT); - } - return; -} - -/* -* Initialize the SPI interface as a SLAVE -* -*/ -void spi_slave_initialize(void) -{ - NVIC_DisableIRQ(SPI_IRQn); - NVIC_ClearPendingIRQ(SPI_IRQn); - NVIC_SetPriority(SPI_IRQn, 0); - NVIC_EnableIRQ(SPI_IRQn); - - /* Configure an SPI peripheral. */ - spi_enable_clock(SPI_SLAVE_BASE); - spi_disable(SPI_SLAVE_BASE); - spi_reset(SPI_SLAVE_BASE); - spi_set_slave_mode(SPI_SLAVE_BASE); - spi_disable_mode_fault_detect(SPI_SLAVE_BASE); - spi_set_peripheral_chip_select_value(SPI_SLAVE_BASE, SPI_CHIP_SEL); - spi_set_clock_polarity(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); - spi_set_clock_phase(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); - spi_set_bits_per_transfer(SPI_SLAVE_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT); - spi_enable_interrupt(SPI_SLAVE_BASE, SPI_IER_RDRF); - spi_enable(SPI_SLAVE_BASE); - ioport_set_pin_level(SPI_IRQ1, false); -} - -/* -* Initialize the SPI interface as a MASTER -* -*/ -void spi_master_initialize(void) -{ - uint32_t ul_sysclk_div = sysclk_get_cpu_hz() / gs_ul_spi_clock; - /* Configure an SPI peripheral. */ - spi_enable_clock(SPI_MASTER_BASE); - spi_disable(SPI_MASTER_BASE); - spi_reset(SPI_MASTER_BASE); - spi_set_lastxfer(SPI_MASTER_BASE); - spi_set_master_mode(SPI_MASTER_BASE); - spi_disable_mode_fault_detect(SPI_MASTER_BASE); - spi_disable_loopback(SPI_MASTER_BASE); - spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL); - spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT); - spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_16_BIT); - spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (ul_sysclk_div)); - spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY); - spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE); - - spi_enable(SPI_MASTER_BASE); -} - -void Slave_timer(void) -{ - if (timer_alt == 0) - { - spi_port_stats(); - timer_alt = 1; - return; - } else if (timer_alt == 1) - { - spi_port_status(); - timer_alt = 2; - return; - } else if (timer_alt == 2) - { - // Send SLAVE port stats if SLAVE is in the clear state - if (slave_ready == true && pending_spi_command == SPI_SEND_READY) - { - spi_p_stats.preamble = SPI_STATS_PREAMBLE; - spi_p_stats.spi_size = sizeof(struct spi_port_stats); - memcpy(&shared_buffer, &spi_p_stats, sizeof(struct spi_port_stats)); - ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something - pending_spi_command = SPI_SEND_STATS; // We are waiting to send port stats - spi_slave_send_size = sizeof(struct spi_port_stats); - spi_slave_send_count = spi_slave_send_size; - timer_alt = 0; - } - return; - } -} - -void spi_port_stats(void) -{ - spi_p_stats.tx_bytes[spi_stats_rr] += readtxbytes(spi_stats_rr+1); - spi_p_stats.rx_bytes[spi_stats_rr] += readrxbytes(spi_stats_rr+1); - spi_stats_rr++; - if (spi_stats_rr == 4) spi_stats_rr = 0; - return; -} - -void spi_port_status(void) -{ - // Copy out the old status so we know if it has changed - spi_p_stats.last_port_status[0] = spi_p_stats.port_status[0]; - spi_p_stats.last_port_status[1] = spi_p_stats.port_status[1]; - spi_p_stats.last_port_status[2] = spi_p_stats.port_status[2]; - spi_p_stats.last_port_status[3] = spi_p_stats.port_status[3]; - // Update port status - spi_p_stats.port_status[0] = (switch_read(30) & 32) >> 5; - spi_p_stats.port_status[1] = (switch_read(46) & 32) >> 5; - spi_p_stats.port_status[2] = (switch_read(62) & 32) >> 5; - spi_p_stats.port_status[3] = (switch_read(78) & 32) >> 5; - return; -} - -/* -* Master ready function -* -*/ -void MasterReady(void) -{ - spi_write(SPI_MASTER_BASE, 0xaa, 0, 0); - master_ready = true; - return; -} - -// ##################### SPI MASTER Send and Receive Functions ##################### - -/* -* Master send function -* -*/ -void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port) -{ - uint8_t uc_pcs; - static uint16_t data; - uint8_t *p_buffer; - uint8_t outport; - - uint8_t spi_head_buffer[SPI_HEADER_SIZE] = {0}; - - if (port < 255) - { - outport = port; - phys10_port_stats[port-1].tx_packets++; - phys13_port_stats[port-1].tx_packets++; - } else { - port = 255; - if (port_status[4] == 1) phys10_port_stats[4].tx_packets++; - if (port_status[4] == 1) phys13_port_stats[4].tx_packets++; - if (port_status[5] == 1) phys10_port_stats[5].tx_packets++; - if (port_status[5] == 1) phys13_port_stats[5].tx_packets++; - if (port_status[6] == 1) phys10_port_stats[6].tx_packets++; - if (port_status[6] == 1) phys13_port_stats[6].tx_packets++; - if (port_status[7] == 1) phys10_port_stats[7].tx_packets++; - if (port_status[7] == 1) phys13_port_stats[7].tx_packets++; - } - // Prepare header (shared_buffer already contains the packet data) - spi_packet = &spi_head_buffer; - spi_packet->preamble = SPI_PACKET_PREAMBLE; - spi_packet->ul_rcv_size = ul_size; - spi_packet->spi_crc = 0; - // Calculate CRC value - for(int x = 0;xspi_crc += p_uc_data[x]; - } - spi_packet->tag = port; - spi_packet->spi_size = SPI_HEADER_SIZE + ul_size; - - TRACE("stacking.c: Sending packet to slave (%d bytes for port %d)", ul_size, port); - - // Send the SPI packet header - for(uint16_t ct=0; ct>8); // upper 8 bits - - spi_write(SPI_MASTER_BASE, 0xbb, 0, 0); - // MAY CAUSE TIMING PROBLEMS - if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) - { - if(spi_count == 4) - { - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) - { - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - } - } - } - spi_count+=2; - while ((spi_read_status(SPI_MASTER_BASE) & SPI_SR_RDRF) == 0); - } - ////printf("stacking.c: ------- ------- rtt %d\r\n", sys_get_ms() - rcv_time); - - TRACE("stacking.c: MASTER received preamble - %x, %x", shared_buffer[0], shared_buffer[1]); - if (!((shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) || (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC))) - { - TRACE("stacking.c: ERROR - BAD SPI HEADER PREAMBLE"); - spi_debug.master_rx_error_bad_preamble++; - return; - } - - if (shared_buffer[0] == 0xBC && shared_buffer[1] == 0xBC) - { - /* Process Received SPI Packet */ - spi_crc_rcv = 0; - spi_packet = &shared_buffer; - if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) - { - TRACE("stacking.c: ERROR - BAD PACKET SIZE"); - spi_debug.master_rx_error_bad_size++; - return; // Packet size is corrupt - } - for(int x = 0;xul_rcv_size;x++) - { - spi_crc_rcv += spi_packet->pkt_buffer[x]; - } - // Make sure we received the entire packet - if (spi_packet->spi_crc != spi_crc_rcv) - { - TRACE("stacking.c: Corrupt slave packet CRC mismatch %x != %x",spi_packet->spi_crc ,spi_crc_rcv); - spi_debug.master_rx_error_bad_crc++; - return; - } - TRACE("stacking.c: received packet (%d bytes)", spi_packet->ul_rcv_size); - // Copy packet into Ethernet buffer - memcpy(gs_uc_eth_buffer, &spi_packet->pkt_buffer, GMAC_FRAME_LENTGH_MAX); - // Update port stats - phys10_port_stats[spi_packet->tag-1].rx_packets++; - phys13_port_stats[spi_packet->tag-1].rx_packets++; - // Send packet to OpenFlow table lookup function for processing - nnOF_tablelookup(gs_uc_eth_buffer, &spi_packet->ul_rcv_size, spi_packet->tag); - ////printf("stacking.c: ------- ------- response ok\r\n"); - spi_debug.master_rx_count++; - return; - } - else if (shared_buffer[0] == 0xAB && shared_buffer[1] == 0xAB) - { - /* Process Received Port Stats */ - TRACE("stacking.c: %d bytes of port stats data received from slave", spi_count); - memcpy(&spi_p_stats, &shared_buffer, sizeof(struct spi_port_stats)); - port_status[4] = spi_p_stats.port_status[0]; - port_status[5] = spi_p_stats.port_status[1]; - port_status[6] = spi_p_stats.port_status[2]; - port_status[7] = spi_p_stats.port_status[3]; - - if (OF_Version == 1) - { - phys10_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; - phys10_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; - phys10_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; - phys10_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; - phys10_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; - phys10_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; - phys10_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; - phys10_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; - } - else if (OF_Version == 4) - { - phys13_port_stats[4].tx_bytes += spi_p_stats.tx_bytes[0]; - phys13_port_stats[4].rx_bytes += spi_p_stats.rx_bytes[0]; - phys13_port_stats[5].tx_bytes += spi_p_stats.tx_bytes[1]; - phys13_port_stats[5].rx_bytes += spi_p_stats.rx_bytes[1]; - phys13_port_stats[6].tx_bytes += spi_p_stats.tx_bytes[2]; - phys13_port_stats[6].rx_bytes += spi_p_stats.rx_bytes[2]; - phys13_port_stats[7].tx_bytes += spi_p_stats.tx_bytes[3]; - phys13_port_stats[7].rx_bytes += spi_p_stats.rx_bytes[3]; - } - } - return; -} - -// ##################### SPI SLAVE Send and Receive Functions ##################### - -/* -* SPI interface IRQ handler -* Used to receive data from the stacking interface -* -*/ -void SPI_Handler(void) -{ - static uint16_t data; - static uint32_t receive_timeout = 0; // Timeout for SPI data receive (MASTER->SLAVE) - uint8_t uc_pcs; - - if (slave_ready == false) // Is this the first data we have received? - { - if (spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) - { - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xaa) - { - ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ - slave_ready = true; - } - return; - } - } - - if(pending_spi_command == SPI_SEND_PKT || pending_spi_command == SPI_SEND_STATS) // Send data to master - { - if (spi_slave_send_count <= 0) - { - // Flush out last two bytes - if (spi_dummy_bytes < 2) - { - spi_write(SPI_SLAVE_BASE, 0xff, 0, 0); // ***** - spi_dummy_bytes++; - return; - } - pending_spi_command = SPI_SEND_READY; // Clear the pending command - ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done - spi_dummy_bytes = 0; - } - else - { - while(spi_slave_send_count > 0) - { - spi_write(SPI_SLAVE_BASE, *(uint16_t*)&shared_buffer[spi_slave_send_size - spi_slave_send_count], 0, 0); - spi_slave_send_count-=2; - // Wait for master to send the next byte - uint16_t timeout = 0; - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0) - { - if(timeout > 100) - { - pending_spi_command = SPI_SEND_READY; // Clear the pending command - ioport_set_pin_level(SPI_IRQ1, false); // turn off the IRQ because we are done - - spi_debug.slave_tx_error_timeout++; - return; - } - else - { - timeout++; - } - } - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - } - spi_debug.slave_tx_count++; - } - return; - } - - if(pending_spi_command == SPI_SEND_READY) - { - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - if (data == 0xBCBC) - { - pending_spi_command = SPI_RECEIVE; - } - return; - } - - if(pending_spi_command == SPI_RECEIVE) - { - // ***** Modified MASTER -> SLAVE receiver ***** - static uint16_t spi_count = 2; - static uint16_t spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - - // Write preamble to SPI packet header - shared_buffer[0] = 0xBC; - shared_buffer[1] = 0xBC; - - /***** Receive the rest of the packet *****/ - - while(spi_count < (spi_read_size-1)) - { - spi_write(SPI_SLAVE_BASE, 0xbb, 0, 0); - uint16_t timeout = 0; - while ((spi_read_status(SPI_SLAVE_BASE) & SPI_SR_RDRF) == 0) - { - if(timeout > 100) - { - pending_spi_command = SPI_SEND_READY; // Clear the pending command - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - spi_debug.slave_rx_error_timeout++; - return; - } - else - { - timeout++; - } - } - spi_read(SPI_SLAVE_BASE, &data, &uc_pcs); - - shared_buffer[spi_count] = data; // lower 8 bits - shared_buffer[spi_count+1] = (data>>8); // upper 8 bits - - if(spi_read_size == GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE && spi_count == 4) - { - spi_read_size = shared_buffer[2] + (shared_buffer[3]*256); - if(spi_read_size > GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE) - { - // ERROR: over-sized packet data - // Clean up and return - pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - spi_debug.slave_rx_error_bad_size++; - return; - } - } - - // Increment the counter - spi_count+=2; - } - - /***** Process the received packet *****/ - - uint32_t spi_crc_rcv = 0; - spi_packet = &shared_buffer; - - // Check against maximum packet size - if (spi_packet->ul_rcv_size > GMAC_FRAME_LENTGH_MAX) - { - // ERROR: payload data too large - // Clean up and return - pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - spi_debug.slave_rx_error_bad_size++; - return; - } - - // Calculated CRC of the received data - for(uint16_t ct=0; ctul_rcv_size; ct++) - { - spi_crc_rcv += spi_packet->pkt_buffer[ct]; - } - - // Check calculated CRC against received CRC - if (spi_packet->spi_crc != spi_crc_rcv) - { - // ERROR: corrupt packet - // Clean up and return - pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - spi_debug.slave_rx_error_bad_crc++; - return; - } - - if (spi_packet->tag == 255) - { - gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, OFPP13_FLOOD, 0); - } - else if (spi_packet->tag <= 8) - { - gmac_write(&spi_packet->pkt_buffer, spi_packet->ul_rcv_size, spi_packet->tag-4, 0); - } - // Packet receive complete - // Clean up and return - pending_spi_command = SPI_SEND_READY; - spi_count = 2; - spi_read_size = GMAC_FRAME_LENTGH_MAX + SPI_HEADER_SIZE; - ////slavemaster_test(); - spi_debug.slave_rx_count++; - return; - } - -} - -// ##################### SPI Test Functions ##################### - -uint8_t masterslave_test(void) -{ - uint8_t pattern = 0; - for(uint16_t i=0;i<1400;i++) - { - shared_buffer[i] = pattern++; - } - rcv_time = sys_get_ms(); - MasterStackSend(&shared_buffer, 1400, 8); - return; -} - -uint8_t slavemaster_test(void) -{ - // Note: the pending check may need to be moved outside of the function call - if (slave_ready == true && pending_spi_command == SPI_SEND_READY) - { - // PREPARE TEST PACKET from SLAVE to MASTER - spi_packet = &shared_buffer; - spi_packet->preamble = SPI_PACKET_PREAMBLE; - spi_packet->ul_rcv_size = 1400; - spi_packet->spi_crc = 0; - uint8_t*ind_ptr = &spi_packet->pkt_buffer; - uint8_t walk = 0; - for(uint16_t x = 0;x<1400;x++) - { - ind_ptr[x] = walk; - spi_packet->spi_crc += walk; - walk++; - } - spi_packet->tag = 2 + 4; - spi_packet->spi_size = SPI_HEADER_SIZE + 1400; - pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet - spi_slave_send_size = spi_packet->spi_size; - spi_slave_send_count = spi_slave_send_size; - ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something - } - return; -} \ No newline at end of file diff --git a/ZodiacFX/src/stacking.h b/ZodiacFX/src/stacking.h deleted file mode 100644 index 36e0243..0000000 --- a/ZodiacFX/src/stacking.h +++ /dev/null @@ -1,94 +0,0 @@ -/** - * @file - * command.c - * - * This file contains the command line functions - * - */ - -/* - * This file is part of the Zodiac FX firmware. - * Copyright (c) 2016 Northbound Networks. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Author: Paul Zanna - * - * - */ - - -#ifndef STACKING_H_ -#define STACKING_H_ - -#define SPI_Handler SPI_Handler -#define SPI_IRQn SPI_IRQn - -#define SPI_SEND_READY 0 -#define SPI_SEND_STATS 1 -#define SPI_SEND_PKT 2 -#define SPI_RECEIVE 3 -#define SPI_RCV_PREAMBLE 4 -#define SPI_STATS_PREAMBLE 0xABAB -#define SPI_PACKET_PREAMBLE 0xBCBC -#define SPI_SEND_WAIT 0 -#define SPI_HEADER_SIZE 14 - -struct spi_port_stats { - uint16_t preamble; - uint16_t spi_size; - uint8_t port_status[4]; - uint8_t last_port_status[4]; - uint64_t rx_bytes[4]; - uint64_t tx_bytes[4]; - uint64_t rx_dropped[4]; - uint64_t tx_dropped[4]; -}; - -struct spi_packet { - uint16_t preamble; // Transmission preamble - uint16_t spi_size; // SPI transmission size - uint32_t ul_rcv_size; // Actual packet size - uint32_t spi_crc; // Calculated CRC of packet - uint8_t tag; // Port number (1-8, or 255) - uint8_t pad; // Pad to 14 bytes - uint8_t pkt_buffer[GMAC_FRAME_LENTGH_MAX]; -}; - -struct spi_debug_stats { - uint32_t master_tx_count; - uint32_t master_rx_count; - uint32_t master_rx_error_bad_preamble; - uint32_t master_rx_error_bad_size; - uint32_t master_rx_error_bad_crc; - uint32_t slave_tx_count; - uint32_t slave_rx_count; - uint32_t slave_tx_error_timeout; - uint32_t slave_rx_error_bad_preamble; - uint32_t slave_rx_error_bad_size; - uint32_t slave_rx_error_bad_crc; - uint32_t slave_rx_error_timeout; -}; - -void stacking_init(bool master); -void MasterReady(void); -void MasterStackSend(uint8_t *p_uc_data, uint16_t ul_size, uint32_t port); -void MasterStackRcv(void); -void Slave_timer(void); - -// ***** Stacking Test Functions ***** -uint8_t masterslave_test(void); // Send pattern from master -> slave -uint8_t slavemaster_test(void); // Send pattern from slave -> master - -#endif /* STACKING_H_ */ \ No newline at end of file diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index fdb8f0a..d323cdd 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -33,7 +33,6 @@ #include "trace.h" #include "openflow/openflow.h" #include "switch.h" -#include "stacking.h" #include "conf_eth.h" #include "command.h" #include "timers.h" From c7913f511e6784e2b4af13a37a528cf75c0f6210 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:24:27 +1000 Subject: [PATCH 02/23] Remove CLI SPI debug stats --- ZodiacFX/src/command.c | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 3afb6b8..386b4a7 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -84,9 +84,6 @@ uint8_t uCLIContext = 0; struct arp_header arp_test; uint8_t esc_char = 0; -// ####### SPI debug output ####### -extern struct spi_debug_stats spi_debug; - // Internal Functions void saveConfig(void); void command_root(char *command, char *param1, char *param2, char *param3); @@ -1641,12 +1638,6 @@ void command_debug(char *command, char *param1, char *param2, char *param3) return; } - if (strcmp(command, "spi")==0) - { - //stack_write(atoi(param1)); - return; - } - if (strcmp(command, "mem")==0) { printf("mem total: %d\r\n", membag_get_total()); @@ -1663,32 +1654,6 @@ void command_debug(char *command, char *param1, char *param2, char *param3) return; } - if (strcmp(command, "spi_stats")==0) - { - printf("master tx packets: %d\r\nmaster rx packets: %d\r\nmaster rx bad size: %d\r\nmaster rx bad preamble: %d\r\nmaster rx bad crc: %d\r\n",\ - spi_debug.master_tx_count,\ - spi_debug.master_rx_count,\ - spi_debug.master_rx_error_bad_size,\ - spi_debug.master_rx_error_bad_preamble,\ - spi_debug.master_rx_error_bad_crc - ); - return; - } - - if (strcmp(command, "spi_stats_slave")==0) - { - printf("slave tx packets: %d\r\nslave rx packets: %d\r\nslave tx timeout errors: %d\r\nslave rx timeout errors: %d\r\nslave rx bad size: %d\r\nslave rx bad preamble: %d\r\nslave rx bad crc: %d\r\n",\ - spi_debug.slave_tx_count,\ - spi_debug.slave_rx_count,\ - spi_debug.slave_tx_error_timeout,\ - spi_debug.slave_rx_error_timeout,\ - spi_debug.slave_rx_error_bad_size,\ - spi_debug.slave_rx_error_bad_preamble,\ - spi_debug.slave_rx_error_bad_crc - ); - return; - } - // Unknown Command response printf("Unknown command\r\n"); return; From 531fc4c1551a2ab81ebd369fc8cae5077953ae12 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:30:19 +1000 Subject: [PATCH 03/23] Remove stacking tasks --- ZodiacFX/src/switch.c | 91 +++++++++---------------------------------- ZodiacFX/src/switch.h | 2 - 2 files changed, 18 insertions(+), 75 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index d323cdd..3fc7978 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -51,8 +51,6 @@ extern uint8_t pending_spi_command; extern struct spi_packet *spi_packet; extern bool slave_ready; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; -extern uint16_t spi_slave_send_size; -extern uint16_t spi_slave_send_count; // Local variables gmac_device_t gs_gmac_dev; @@ -62,7 +60,6 @@ struct ofp13_port_stats phys13_port_stats[8]; uint8_t port_status[8]; uint8_t last_port_status[8]; uint8_t total_ports = 4; -int slave_timer = 0; uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; uint8_t stats_rr = 0; @@ -507,32 +504,6 @@ void task_switch(struct netif *netif) uint8_t tag = 0; int8_t in_port = 0; - // Check if the slave device has a packet to send us - if(masterselect == false && ioport_get_pin_level(SPI_IRQ1) && stackenabled == true) - { - MasterStackRcv(); - } - - // Check if the slave device is connected and enable stacking - if(masterselect == false && !ioport_get_pin_level(SPI_IRQ1) && stackenabled == false) - { - MasterReady(); // Let the slave know the master is ready - stackenabled = true; - total_ports = 8; - } - - // Slave house keeping timer - if(masterselect == true) - { - if((sys_get_ms() - slave_timer) > 500) // every 500 ms (0.5 secs) - { - slave_timer = sys_get_ms(); - Slave_timer(); // Slave timer - } - - } - - /* Main packet processing loop */ uint32_t dev_read = gmac_dev_read(&gs_gmac_dev, (uint8_t *) gs_uc_eth_buffer, sizeof(gs_uc_eth_buffer), &ul_rcv_size); if (dev_read == GMAC_OK) @@ -550,55 +521,29 @@ void task_switch(struct netif *netif) } } - if(masterselect == false) // Only process packets if board is set to MASTER - { - if (ul_rcv_size > 0) - { - uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); - uint8_t tag = *tail_tag + 1; - if (Zodiac_Config.OFEnabled == OF_ENABLED && Zodiac_Config.of_port[tag-1] == 1) - { - phys10_port_stats[tag-1].rx_packets++; - phys13_port_stats[tag-1].rx_packets++; - ul_rcv_size--; // remove the tail first - nnOF_tablelookup((uint8_t *) gs_uc_eth_buffer, &ul_rcv_size, tag); - return; - } else { - TRACE("switch.c: %d byte received from controller", ul_rcv_size); - struct pbuf *p; - p = pbuf_alloc(PBUF_RAW, ul_rcv_size+1, PBUF_POOL); - memcpy(p->payload, &gs_uc_eth_buffer,(ul_rcv_size-1)); - p->len = ul_rcv_size-1; - p->tot_len = ul_rcv_size-1; - netif->input(p, netif); - pbuf_free(p); - return; - } - } - } else + // Process packet + if (ul_rcv_size > 0) { - if (slave_ready == true && pending_spi_command == SPI_SEND_READY) + uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); + uint8_t tag = *tail_tag + 1; + if (Zodiac_Config.OFEnabled == OF_ENABLED && Zodiac_Config.of_port[tag-1] == 1) { - uint8_t* tail_tag = (uint8_t*)(gs_uc_eth_buffer + (int)(ul_rcv_size)-1); - uint8_t tag = *tail_tag + 1; phys10_port_stats[tag-1].rx_packets++; phys13_port_stats[tag-1].rx_packets++; ul_rcv_size--; // remove the tail first - spi_packet = &shared_buffer; - spi_packet->preamble = SPI_PACKET_PREAMBLE; - spi_packet->ul_rcv_size = ul_rcv_size; - spi_packet->spi_crc = 0; - for(int x = 0;xspi_crc += gs_uc_eth_buffer[x]; - } - spi_packet->tag = tag + 4; - spi_packet->spi_size = SPI_HEADER_SIZE + ul_rcv_size; - memcpy(&spi_packet->pkt_buffer, &gs_uc_eth_buffer, ul_rcv_size); - pending_spi_command = SPI_SEND_PKT; // We are waiting to forward the packet - spi_slave_send_size = spi_packet->spi_size; - spi_slave_send_count = spi_slave_send_size; - ioport_set_pin_level(SPI_IRQ1, true); // Set the IRQ to signal the slave wants to send something + nnOF_tablelookup((uint8_t *) gs_uc_eth_buffer, &ul_rcv_size, tag); + return; + } + else + { + TRACE("switch.c: %d byte received from controller", ul_rcv_size); + struct pbuf *p; + p = pbuf_alloc(PBUF_RAW, ul_rcv_size+1, PBUF_POOL); + memcpy(p->payload, &gs_uc_eth_buffer,(ul_rcv_size-1)); + p->len = ul_rcv_size-1; + p->tot_len = ul_rcv_size-1; + netif->input(p, netif); + pbuf_free(p); return; } } diff --git a/ZodiacFX/src/switch.h b/ZodiacFX/src/switch.h index f51edb6..33c72aa 100644 --- a/ZodiacFX/src/switch.h +++ b/ZodiacFX/src/switch.h @@ -44,8 +44,6 @@ void update_port_stats(void); void update_port_status(void); void disableOF(void); void enableOF(void); -void stacking_init(bool master); -void MasterStackRcv(void); int readtxbytes(int port); int readrxbytes(int port); From 734cd2eb8ccdcfcb7cf3bac0145f2837d76e0dbb Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:35:23 +1000 Subject: [PATCH 04/23] Remove stacking initialisations --- ZodiacFX/src/main.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index 7b1e664..bf6d49f 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -130,13 +130,6 @@ int main (void) board_init(); get_serial(&uid_buf); - // Set up the GPIO pin for the Mater Select jumper - ioport_init(); - ioport_set_pin_dir(MASTER_SEL, IOPORT_DIR_INPUT); - - masterselect = ioport_get_pin_level(MASTER_SEL); // true = slave - stacking_init(masterselect); // Initialise the stacking connector as either master or slave - irq_initialize_vectors(); // Initialize interrupt vector table support. cpu_irq_enable(); // Enable interrupts From 43b1231c2563bdff7fd264fb979e585963279c63 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:41:20 +1000 Subject: [PATCH 05/23] Revert gmac_write function to dev_80 version --- ZodiacFX/src/switch.c | 50 +++++++------------------------------------ 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 3fc7978..63f9e2d 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -314,52 +314,14 @@ void update_port_status(void) * @param port - the port to send the data out from. * */ -void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) +void gmac_write(uint8_t *p_buffer, uint16_t ul_size, uint8_t port) { - TRACE("switch.c: gmac_write to port 0x%X (%d bytes)", port, ul_size); - // Convert OpenFlow port to physical port number - if (port == OFPP_FLOOD || port == OFPP_ALL || port == OFPP13_FLOOD || port == OFPP13_ALL) // Send packet out all ports except the port it arrived on - { - TRACE("switch.c: Packet out FLOOD (%d bytes)", ul_size); - if(masterselect == false) - { - MasterStackSend(p_buffer, ul_size, port); // Send it slave - if (inport < 5) - { - port = (15 - NativePortMatrix) - (1<<(inport-1)); - } else { - port = 15 - NativePortMatrix; - } - } else { - inport -= 4; - port = (15 - (1<<(inport-1))); - } - } else if (port == OFPP13_IN_PORT) // Send it back out the port it arrived on - { - port = inport; - TRACE("switch.c: Output to in_port %d (%d bytes)", port, ul_size); - } else if (port < 5) // Send it out the specified port - { - port = 1 << (port-1); - } else if (port > 4 && port < 128) - { - if(masterselect == false) // If we are the master then send to the slave - { - TRACE("switch13.c: Sending packet to slave to send out port %d (%d bytes)", port, ul_size); - MasterStackSend(p_buffer, ul_size, port); // Send it slave - return; - } - // If slave then write to port - port -= 4; - port = 1 << (port-1); - } - - TRACE("switch.c: Writing data to switch port matrix %d (%d bytes)", port, ul_size); if (ul_size > GMAC_FRAME_LENTGH_MAX) { return; } - + + // Update port stats if (port & 1) phys10_port_stats[0].tx_packets++; if (port & 2) phys10_port_stats[1].tx_packets++; if (port & 4) phys10_port_stats[2].tx_packets++; @@ -368,6 +330,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) if (port & 2) phys13_port_stats[1].tx_packets++; if (port & 4) phys13_port_stats[2].tx_packets++; if (port & 8) phys13_port_stats[3].tx_packets++; + // Add padding if (ul_size < 60) { @@ -377,7 +340,9 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) last_byte = gmacbuffer + 60; *last_byte = port; gmac_dev_write(&gs_gmac_dev, &gmacbuffer, 61, NULL); - } else { + } + else + { memcpy(&gmacbuffer,p_buffer, ul_size); uint8_t *last_byte; last_byte = gmacbuffer + ul_size; @@ -385,6 +350,7 @@ void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport) ul_size++; // Increase packet size by 1 to allow for the tail tag. uint32_t write_size = gmac_dev_write(&gs_gmac_dev, &gmacbuffer, ul_size, NULL); } + return; } From 20fe76ec1e2f7e8154f8697be7e762a708e8899d Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:43:50 +1000 Subject: [PATCH 06/23] Remove stackenabled variable --- ZodiacFX/src/command.c | 3 --- ZodiacFX/src/http.c | 15 +-------------- ZodiacFX/src/main.c | 1 - ZodiacFX/src/openflow/openflow.c | 2 -- ZodiacFX/src/openflow/openflow_10.c | 5 ----- ZodiacFX/src/openflow/openflow_13.c | 5 ----- ZodiacFX/src/switch.c | 1 - 7 files changed, 1 insertion(+), 31 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 386b4a7..f4428c4 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -67,7 +67,6 @@ 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 bool masterselect; -extern bool stackenabled = false; extern bool trace = false; extern struct tcp_pcb *tcp_pcb; extern uint8_t port_status[8]; @@ -558,8 +557,6 @@ void command_config(char *command, char *param1, char *param2, char *param3) } else { printf(" Force OpenFlow version: Disabled\r\n"); } - if (stackenabled == true) printf(" Stacking Status: Enabled\r\n"); - if (stackenabled == false) printf(" Stacking Status: Disabled\r\n"); 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("\r\n-------------------------------------------------------------------------\r\n\n"); diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 3e0a9f6..7cef6b4 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -91,8 +91,6 @@ static bool restart_required = false; // Track if any configuration changes are static bool file_upload = false; // Multi-part firmware file upload flag static bool post_pending = false; -extern bool stackenabled; - static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err); static err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err); void http_send(char *buffer, struct tcp_pcb *pcb, bool out); @@ -2109,18 +2107,7 @@ static uint8_t interfaceCreate_Home(void) "CPU Temp: %d C
"\ "Uptime: %02d:%02d
"\ ); - if(stackenabled == true) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "Stacking: enabled" - ); - } - else - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "Stacking: disabled" - ); - } + if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ "

"\ "
"\ diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index bf6d49f..2765678 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -52,7 +52,6 @@ struct netif gs_net_if; struct zodiac_config Zodiac_Config; int charcount, charcount_last; bool masterselect; -bool stackenabled; int portmap[4]; int32_t ul_temp; uint8_t NativePortMatrix; diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index c2aed17..07cae39 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -45,7 +45,6 @@ extern struct zodiac_config Zodiac_Config; extern uint8_t port_status[8]; extern struct ofp10_port_stats phys10_port_stats[8]; extern struct ofp13_port_stats phys13_port_stats[8]; -extern bool stackenabled; // Local Variables struct ofp_switch_config Switch_config; @@ -355,7 +354,6 @@ void task_openflow(void) { fast_of_timer = sys_get_ms(); nnOF_timer(); - ////if (stackenabled == true) masterslave_test(); if (heartbeat > (HB_INTERVAL * 2) && tcp_con_state == 1) //If we haven't heard anything from the controller for more then the heartbeat interval send an echo request { diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 09e5b9f..99d2d4b 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -58,7 +58,6 @@ extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern struct zodiac_config Zodiac_Config; extern struct ofp_switch_config Switch_config; extern uint8_t total_ports; -extern bool stackenabled; //Internal Functions void packet_in(uint8_t *buffer, uint16_t ul_size, uint8_t port, uint8_t reason); @@ -411,10 +410,6 @@ void features_reply10(uint32_t xid) { if(Zodiac_Config.of_port[n]==1)numofports++; } - if(stackenabled == true) - { - numofports += 4; // Add the slave ports - } struct ofp10_switch_features features; struct ofp10_phy_port phys_port[numofports]; uint8_t buf[256]; diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index df19919..45d5e0d 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -68,7 +68,6 @@ extern uint8_t NativePortMatrix; extern bool reply_more_flag; extern uint32_t reply_more_xid; extern uint8_t total_ports; -extern bool stackenabled; extern int meter_handler(uint32_t id, uint16_t bytes); // Internal functions @@ -891,10 +890,6 @@ int multi_portdesc_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) { if(Zodiac_Config.of_port[n]==1) numofports++; } - if(stackenabled == true) - { - numofports += 4; // Add the slave ports - } struct ofp13_multipart_reply *reply; struct ofp13_port phys_port[numofports]; uint16_t len = sizeof(struct ofp13_multipart_reply) + sizeof(phys_port); diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 63f9e2d..8490abb 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -46,7 +46,6 @@ extern struct zodiac_config Zodiac_Config; extern int OF_Version; extern uint8_t NativePortMatrix; extern bool masterselect; -extern bool stackenabled; extern uint8_t pending_spi_command; extern struct spi_packet *spi_packet; extern bool slave_ready; From 28ffbf1f050884078bf7927d735058880c034c85 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:44:51 +1000 Subject: [PATCH 07/23] Remove masterselect variable --- ZodiacFX/src/main.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ZodiacFX/src/main.c b/ZodiacFX/src/main.c index 2765678..4010674 100644 --- a/ZodiacFX/src/main.c +++ b/ZodiacFX/src/main.c @@ -51,7 +51,6 @@ struct netif gs_net_if; struct zodiac_config Zodiac_Config; int charcount, charcount_last; -bool masterselect; int portmap[4]; int32_t ul_temp; uint8_t NativePortMatrix; @@ -194,12 +193,7 @@ int main (void) { task_switch(&gs_net_if); task_command(cCommand, cCommand_last); - // Only run the following tasks if set to Master - if(masterselect == false) - { - //task_command(cCommand, cCommand_last); - sys_check_timeouts(); - task_openflow(); - } + sys_check_timeouts(); + task_openflow(); } } From aadd986af6244abb3650829e3823b5bb5fff19b1 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:49:55 +1000 Subject: [PATCH 08/23] Remove stacking reference in openflow features reply --- ZodiacFX/src/openflow/openflow_10.c | 4 ++-- ZodiacFX/src/openflow/openflow_13.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 99d2d4b..099adfc 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -433,9 +433,9 @@ void features_reply10(uint32_t xid) memcpy(&buf, &features, sizeof(struct ofp10_switch_features)); update_port_status(); //update port status - for(l = 0; l< total_ports; l++) + for(l = 0; l 3) // If l > 3 then stacking is enabled so include the 4 port from the slave + if(Zodiac_Config.of_port[l] == 1) { phys_port[j].port_no = HTONS(l+1); for(k = 0; k<6; k++) // Generate random MAC address diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 45d5e0d..fd3b7aa 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -906,9 +906,9 @@ int multi_portdesc_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) uint8_t mac[] = {0x00,0x00,0x00,0x00,0x00,0x00}; update_port_status(); //update port status - for(int l = 0; l< total_ports; l++) + for(int l = 0; l 3) // If l > 3 then stacking is enabled so include the 4 port from the slave + if(Zodiac_Config.of_port[l] == 1) { phys_port[j].port_no = htonl(l+1); for(int k = 0; k<6; k++) // Generate random MAC address From f8bd8522b21b9f87beeac48ca59680d865be6c76 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:51:42 +1000 Subject: [PATCH 09/23] Remove unused externs --- ZodiacFX/src/command.c | 1 - ZodiacFX/src/switch.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index f4428c4..1c7157c 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -66,7 +66,6 @@ extern struct ofp13_port_stats phys13_port_stats[8]; 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 bool masterselect; extern bool trace = false; extern struct tcp_pcb *tcp_pcb; extern uint8_t port_status[8]; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 8490abb..c11e7e7 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -45,10 +45,8 @@ extern struct tcp_conn tcp_conn; extern struct zodiac_config Zodiac_Config; extern int OF_Version; extern uint8_t NativePortMatrix; -extern bool masterselect; extern uint8_t pending_spi_command; extern struct spi_packet *spi_packet; -extern bool slave_ready; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; // Local variables From 3e061a05123550893fd31bfa088acc649edd0db4 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 10:51:51 +1000 Subject: [PATCH 10/23] Update function prototype --- ZodiacFX/src/switch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/switch.h b/ZodiacFX/src/switch.h index 33c72aa..e4b132a 100644 --- a/ZodiacFX/src/switch.h +++ b/ZodiacFX/src/switch.h @@ -37,7 +37,7 @@ void spi_init(void); void switch_init(void); void task_switch(struct netif *netif); -void gmac_write(uint8_t *p_buffer, uint16_t ul_size, int port, int inport); +void gmac_write(uint8_t *p_buffer, uint16_t ul_size, uint8_t port); int switch_read(uint8_t param1); int switch_write(uint8_t param1, uint8_t param2); void update_port_stats(void); From 9fe295e4dcc3820deeed2b106dfeb4745da40e73 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:06:39 +1000 Subject: [PATCH 11/23] Modify gmac_write calls --- ZodiacFX/src/ksz8795clx/ethernet_phy.c | 2 +- ZodiacFX/src/openflow/openflow_10.c | 4 ++-- ZodiacFX/src/openflow/openflow_13.c | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ZodiacFX/src/ksz8795clx/ethernet_phy.c b/ZodiacFX/src/ksz8795clx/ethernet_phy.c index f734ba8..c529f4f 100644 --- a/ZodiacFX/src/ksz8795clx/ethernet_phy.c +++ b/ZodiacFX/src/ksz8795clx/ethernet_phy.c @@ -289,7 +289,7 @@ err_t ethernetif_init(struct netif *netif) static err_t gmac_low_level_output(struct netif *netif, struct pbuf *p) { - gmac_write(p->payload, p->len, 128, 0); + gmac_write(p->payload, p->len, 128); } diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 099adfc..18992e2 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -179,7 +179,7 @@ void nnOF10_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) if (pisize > packet_size) pisize = packet_size; packet_in(p_uc_data, pisize, port, OFPR_ACTION); } - gmac_write(p_uc_data, packet_size, ntohs(action_out->port), port); + gmac_write(p_uc_data, packet_size, ntohs(action_out->port)); break; case OFPAT10_SET_DL_SRC: @@ -764,7 +764,7 @@ void packet_out(struct ofp_header *msg) nnOF_tablelookup(ptr, &size, NTOHS(*iport)); return; } - gmac_write(ptr, size, NTOHS(*eport), NTOHS(*iport)); + gmac_write(ptr, size, NTOHS(*eport)); return; } diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index fd3b7aa..566a555 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -233,7 +233,7 @@ void nnOF13_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) break; } - gmac_write(p_uc_data, packet_size, htonl(act_output->port), port); + gmac_write(p_uc_data, packet_size, htonl(act_output->port)); } break; @@ -2025,14 +2025,13 @@ void packet_out13(struct ofp_header *msg) struct ofp13_action_header *act_hdr = po->actions; if (ntohs(act_hdr->type) != OFPAT13_OUTPUT) return; struct ofp13_action_output *act_out = act_hdr; - //uint32_t outPort = htonl(act_out->port); TRACE("openflow_13.c: Packet out port 0x%X (%d bytes)", htonl(act_out->port), size); if (htonl(act_out->port) == OFPP13_TABLE) { nnOF_tablelookup(ptr, &size, inPort); return; } - gmac_write(ptr, size, htonl(act_out->port), inPort); + gmac_write(ptr, size, htonl(act_out->port)); return; } From 1da9de0abebba80f01d500e03166e0896bae7ce8 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:09:18 +1000 Subject: [PATCH 12/23] Remove 8-port display in web interface --- ZodiacFX/src/http.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 7cef6b4..7c2f967 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -2354,15 +2354,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "Port 3"\ "Port 4"\ ); - if (total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "Port 5"\ - "Port 6"\ - "Port 7"\ - "Port 8"\ - ); - } if ( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ ""\ @@ -2417,17 +2408,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) , portStatusch[port_status[0]], portStatusch[port_status[1]], portStatusch[port_status[2]], portStatusch[port_status[3]]\ ); - if (total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "%s"\ - "%s"\ - "%s"\ - "%s"\ - , portStatusch[port_status[4]], portStatusch[port_status[5]], portStatusch[port_status[6]], portStatusch[port_status[7]]\ - ); - } - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ ""\ ""\ @@ -2477,16 +2457,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) ); } } - - if (total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "OpenFlow"\ - "OpenFlow"\ - "OpenFlow"\ - "OpenFlow"\ - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ ""\ @@ -2535,16 +2505,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) ""\ ); } - - if (total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ - "-"\ - "-"\ - "-"\ - "-"\ - ); - } if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ ""\ From 68bd2c39647f0f979947cbb5604e5ef0bb18c388 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:11:56 +1000 Subject: [PATCH 13/23] Remove 8-port stats in web interface --- ZodiacFX/src/http.c | 141 -------------------------------------------- 1 file changed, 141 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 7c2f967..0bdc5e4 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -70,7 +70,6 @@ extern int iLastMeter; extern struct ofp10_port_stats phys10_port_stats[8]; extern struct ofp13_port_stats phys13_port_stats[8]; extern struct table_counter table_counters[MAX_TABLES]; -extern uint8_t total_ports; // Local Variables struct tcp_pcb *http_pcb; @@ -2534,16 +2533,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].rx_bytes, phys10_port_stats[1].rx_bytes, phys10_port_stats[2].rx_bytes, phys10_port_stats[3].rx_bytes ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].rx_bytes, phys10_port_stats[5].rx_bytes, phys10_port_stats[6].rx_bytes, phys10_port_stats[7].rx_bytes - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2556,16 +2545,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].tx_bytes, phys10_port_stats[1].tx_bytes, phys10_port_stats[2].tx_bytes, phys10_port_stats[3].tx_bytes ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].tx_bytes, phys10_port_stats[5].tx_bytes, phys10_port_stats[6].tx_bytes, phys10_port_stats[7].tx_bytes - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2578,16 +2557,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].rx_packets, phys10_port_stats[1].rx_packets, phys10_port_stats[2].rx_packets, phys10_port_stats[3].rx_packets ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].rx_packets, phys10_port_stats[5].rx_packets, phys10_port_stats[6].rx_packets, phys10_port_stats[7].rx_packets - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2600,16 +2569,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].tx_packets, phys10_port_stats[1].tx_packets, phys10_port_stats[2].tx_packets, phys10_port_stats[3].tx_packets ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].tx_packets, phys10_port_stats[5].tx_packets, phys10_port_stats[6].tx_packets, phys10_port_stats[7].tx_packets - ); - } if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ) < SHARED_BUFFER_LEN) @@ -2637,16 +2596,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].rx_bytes, phys13_port_stats[1].rx_bytes, phys13_port_stats[2].rx_bytes, phys13_port_stats[3].rx_bytes ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].rx_bytes, phys13_port_stats[5].rx_bytes, phys13_port_stats[6].rx_bytes, phys13_port_stats[7].rx_bytes - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2659,16 +2608,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].tx_bytes, phys13_port_stats[1].tx_bytes, phys13_port_stats[2].tx_bytes, phys13_port_stats[3].tx_bytes ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].tx_bytes, phys13_port_stats[5].tx_bytes, phys13_port_stats[6].tx_bytes, phys13_port_stats[7].tx_bytes - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2681,16 +2620,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].rx_packets, phys13_port_stats[1].rx_packets, phys13_port_stats[2].rx_packets, phys13_port_stats[3].rx_packets ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].rx_packets, phys13_port_stats[5].rx_packets, phys13_port_stats[6].rx_packets, phys13_port_stats[7].rx_packets - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2703,16 +2632,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].tx_packets, phys13_port_stats[1].tx_packets, phys13_port_stats[2].tx_packets, phys13_port_stats[3].tx_packets ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].tx_packets, phys13_port_stats[5].tx_packets, phys13_port_stats[6].tx_packets, phys13_port_stats[7].tx_packets - ); - } if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ) < SHARED_BUFFER_LEN) @@ -2743,16 +2662,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].rx_dropped, phys10_port_stats[1].rx_dropped, phys10_port_stats[2].rx_dropped, phys10_port_stats[3].rx_dropped ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].rx_dropped, phys10_port_stats[5].rx_dropped, phys10_port_stats[6].rx_dropped, phys10_port_stats[7].rx_dropped - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2765,16 +2674,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].tx_dropped, phys10_port_stats[1].tx_dropped, phys10_port_stats[2].tx_dropped, phys10_port_stats[3].tx_dropped ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].tx_dropped, phys10_port_stats[5].tx_dropped, phys10_port_stats[6].tx_dropped, phys10_port_stats[7].tx_dropped - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2787,16 +2686,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys10_port_stats[0].rx_crc_err, phys10_port_stats[1].rx_crc_err, phys10_port_stats[2].rx_crc_err, phys10_port_stats[3].rx_crc_err ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys10_port_stats[4].rx_crc_err, phys10_port_stats[5].rx_crc_err, phys10_port_stats[6].rx_crc_err, phys10_port_stats[7].rx_crc_err - ); - } if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2832,16 +2721,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].rx_dropped, phys13_port_stats[1].rx_dropped, phys13_port_stats[2].rx_dropped, phys13_port_stats[3].rx_dropped ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].rx_dropped, phys13_port_stats[5].rx_dropped, phys13_port_stats[6].rx_dropped, phys13_port_stats[7].rx_dropped - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2854,16 +2733,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].tx_dropped, phys13_port_stats[1].tx_dropped, phys13_port_stats[2].tx_dropped, phys13_port_stats[3].tx_dropped ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].tx_dropped, phys13_port_stats[5].tx_dropped, phys13_port_stats[6].tx_dropped, phys13_port_stats[7].tx_dropped - ); - } snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ @@ -2876,16 +2745,6 @@ static uint8_t interfaceCreate_Display_Ports(uint8_t step) "%"PRIu64""\ , phys13_port_stats[0].rx_crc_err, phys13_port_stats[1].rx_crc_err, phys13_port_stats[2].rx_crc_err, phys13_port_stats[3].rx_crc_err ); - if(total_ports > 4) - { - snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - "%"PRIu64""\ - , phys13_port_stats[4].rx_dropped, phys13_port_stats[5].rx_crc_err, phys13_port_stats[6].rx_crc_err, phys13_port_stats[7].rx_crc_err - ); - } if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN,\ ""\ ""\ From a15023a254aee7f0d7cb6e2866cbc8bfbbfd239f Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:12:28 +1000 Subject: [PATCH 14/23] Clean up stacking-related comments --- ZodiacFX/src/openflow/openflow_10.c | 2 +- ZodiacFX/src/openflow/openflow_13.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 18992e2..79a120c 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -693,7 +693,7 @@ void stats_port_reply(struct ofp_stats_request *msg) } } } - else if (port > 0 && port <= total_ports) // Respond to request for ports 1-4 or 1-8 (stacking) + else if (port > 0 && port <= total_ports) // Respond to request for ports { // Check if port is NOT native if(!(NativePortMatrix & (1<<(port-1)))) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 566a555..2a3d0d9 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -1164,7 +1164,7 @@ int multi_portstats_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg } } } - else if (port > 0 && port <= total_ports) // Respond to request for ports 1-4 or 1-8 (stacking) + else if (port > 0 && port <= total_ports) // Respond to request for ports { // Check if port is NOT native if(!(NativePortMatrix & (1<<(port-1)))) From 97690994726f46e2f587963d6ba50fa5af9e6272 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:17:38 +1000 Subject: [PATCH 15/23] Modify total_ports variable into a macro --- ZodiacFX/src/command.c | 3 +-- ZodiacFX/src/config/config_zodiac.h | 2 ++ ZodiacFX/src/openflow/of_helper.c | 3 +-- ZodiacFX/src/openflow/openflow_10.c | 9 ++++----- ZodiacFX/src/openflow/openflow_13.c | 11 +++++------ ZodiacFX/src/switch.c | 1 - 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 1c7157c..83c90d9 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -69,7 +69,6 @@ extern struct meter_band_stats_array band_stats_array[MAX_METER_13]; extern bool trace = false; extern struct tcp_pcb *tcp_pcb; extern uint8_t port_status[8]; -extern uint8_t total_ports; extern int totaltime; extern int32_t ul_temp; extern int OF_Version; @@ -326,7 +325,7 @@ void command_root(char *command, char *param1, char *param2, char *param3) { int i; printf("\r\n-------------------------------------------------------------------------\r\n"); - for (i=0;i 0 && port <= total_ports) // Respond to request for ports + else if (port > 0 && port <= TOTAL_PORTS) // Respond to request for ports { // Check if port is NOT native if(!(NativePortMatrix & (1<<(port-1)))) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 2a3d0d9..3ee1097 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -67,7 +67,6 @@ extern int multi_pos; extern uint8_t NativePortMatrix; extern bool reply_more_flag; extern uint32_t reply_more_xid; -extern uint8_t total_ports; extern int meter_handler(uint32_t id, uint16_t bytes); // Internal functions @@ -886,7 +885,7 @@ int multi_aggregate_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg int multi_portdesc_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) { int numofports = 0; - for(int n=0;n 0 && port <= total_ports) // Respond to request for ports + else if (port > 0 && port <= TOTAL_PORTS) // Respond to request for ports { // Check if port is NOT native if(!(NativePortMatrix & (1<<(port-1)))) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index c11e7e7..393a8c4 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -56,7 +56,6 @@ struct ofp10_port_stats phys10_port_stats[8]; struct ofp13_port_stats phys13_port_stats[8]; uint8_t port_status[8]; uint8_t last_port_status[8]; -uint8_t total_ports = 4; uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; uint8_t stats_rr = 0; From 5fc225392ab0b5854140b91eacccb25775dc3e1a Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 11:20:21 +1000 Subject: [PATCH 16/23] Clean up unused variables --- ZodiacFX/src/openflow/of_helper.c | 5 ----- ZodiacFX/src/openflow/openflow_10.c | 1 - ZodiacFX/src/switch.c | 2 -- 3 files changed, 8 deletions(-) diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 817d184..9b6439f 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -1227,12 +1227,8 @@ int flow_stats_msg10(char *buffer, int first, int last) int flow_stats_msg13(char *buffer, int first, int last) { struct ofp13_flow_stats flow_stats; - int stats_size = 0; char *buffer_ptr = buffer; - int inst_size; - int stats_len; int len; - int pad = 0; for(int k = first; k Date: Tue, 23 May 2017 11:56:11 +1000 Subject: [PATCH 17/23] Update port stats struct array sizes --- ZodiacFX/src/command.c | 6 +++--- ZodiacFX/src/http.c | 4 ++-- ZodiacFX/src/openflow/of_helper.c | 4 ++-- ZodiacFX/src/openflow/openflow.c | 6 +++--- ZodiacFX/src/openflow/openflow_10.c | 4 ++-- ZodiacFX/src/openflow/openflow_13.c | 4 ++-- ZodiacFX/src/switch.c | 8 ++++---- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ZodiacFX/src/command.c b/ZodiacFX/src/command.c index 83c90d9..8c1befa 100644 --- a/ZodiacFX/src/command.c +++ b/ZodiacFX/src/command.c @@ -61,14 +61,14 @@ extern uint16_t ofp13_oxm_inst_size[MAX_FLOWS_13]; extern struct flows_counter flow_counters[MAX_FLOWS_13]; extern struct flow_tbl_actions *flow_actions10[MAX_FLOWS_13]; extern int iLastFlow; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern struct ofp13_port_stats phys13_port_stats[8]; +extern struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; +extern struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; 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 bool trace = false; extern struct tcp_pcb *tcp_pcb; -extern uint8_t port_status[8]; +extern uint8_t port_status[TOTAL_PORTS]; extern int totaltime; extern int32_t ul_temp; extern int OF_Version; diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index 0bdc5e4..c9f7d45 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -67,8 +67,8 @@ extern struct meter_entry13 *meter_entry[MAX_METER_13]; extern struct meter_band_stats_array band_stats_array[MAX_METER_13]; extern int iLastFlow; extern int iLastMeter; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern struct ofp13_port_stats phys13_port_stats[8]; +extern struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; +extern struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; extern struct table_counter table_counters[MAX_TABLES]; // Local Variables diff --git a/ZodiacFX/src/openflow/of_helper.c b/ZodiacFX/src/openflow/of_helper.c index 9b6439f..5c84566 100644 --- a/ZodiacFX/src/openflow/of_helper.c +++ b/ZodiacFX/src/openflow/of_helper.c @@ -52,8 +52,8 @@ extern int iLastFlow; extern int iLastMeter; extern int OF_Version; extern int totaltime; -extern uint8_t last_port_status[8]; -extern uint8_t port_status[8]; +extern uint8_t last_port_status[TOTAL_PORTS]; +extern uint8_t port_status[TOTAL_PORTS]; 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]; diff --git a/ZodiacFX/src/openflow/openflow.c b/ZodiacFX/src/openflow/openflow.c index 07cae39..27d4ffa 100644 --- a/ZodiacFX/src/openflow/openflow.c +++ b/ZodiacFX/src/openflow/openflow.c @@ -42,9 +42,9 @@ // Global variables extern struct zodiac_config Zodiac_Config; -extern uint8_t port_status[8]; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern struct ofp13_port_stats phys13_port_stats[8]; +extern uint8_t port_status[TOTAL_PORTS]; +extern struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; +extern struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; // Local Variables struct ofp_switch_config Switch_config; diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 0317c3c..46cfad4 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -52,8 +52,8 @@ extern struct table_counter table_counters[MAX_TABLES]; extern int OF_Version; extern bool rcv_freq; extern uint8_t NativePortMatrix; -extern struct ofp10_port_stats phys10_port_stats[8]; -extern uint8_t port_status[8]; +extern struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; +extern uint8_t port_status[TOTAL_PORTS]; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern struct zodiac_config Zodiac_Config; extern struct ofp_switch_config Switch_config; diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index 3ee1097..c40dad7 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -58,9 +58,9 @@ 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]; extern struct flows_counter flow_counters[MAX_FLOWS_13]; -extern struct ofp13_port_stats phys13_port_stats[8]; +extern struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; extern struct table_counter table_counters[MAX_TABLES]; -extern uint8_t port_status[8]; +extern uint8_t port_status[TOTAL_PORTS]; extern struct ofp_switch_config Switch_config; extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; extern int multi_pos; diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index 7dc6cef..caf19df 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -52,10 +52,10 @@ extern uint8_t shared_buffer[SHARED_BUFFER_LEN]; // Local variables gmac_device_t gs_gmac_dev; uint8_t gmacbuffer[GMAC_FRAME_LENTGH_MAX]; -struct ofp10_port_stats phys10_port_stats[8]; -struct ofp13_port_stats phys13_port_stats[8]; -uint8_t port_status[8]; -uint8_t last_port_status[8]; +struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; +struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; +uint8_t port_status[TOTAL_PORTS]; +uint8_t last_port_status[TOTAL_PORTS]; uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; uint8_t stats_rr = 0; From c9055747df93dfeb85112a44c96e884e0ef5ff2e Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 12:34:07 +1000 Subject: [PATCH 18/23] Fix web interface status page --- ZodiacFX/src/http.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/http.c b/ZodiacFX/src/http.c index c9f7d45..23e827f 100644 --- a/ZodiacFX/src/http.c +++ b/ZodiacFX/src/http.c @@ -2105,6 +2105,8 @@ static uint8_t interfaceCreate_Home(void) "Firmware Version: %s
"\ "CPU Temp: %d C
"\ "Uptime: %02d:%02d
"\ + , uid_buf[0], uid_buf[1], uid_buf[2], uid_buf[3]\ + , VERSION, (int)ul_temp, hr, min\ ); if( snprintf(shared_buffer+strlen(shared_buffer), SHARED_BUFFER_LEN-strlen(shared_buffer),\ @@ -2114,8 +2116,7 @@ static uint8_t interfaceCreate_Home(void) ""\ ""\ ""\ - , uid_buf[0], uid_buf[1], uid_buf[2], uid_buf[3]\ - , VERSION, (int)ul_temp, hr, min) < SHARED_BUFFER_LEN) + ) < SHARED_BUFFER_LEN ) { return 1; } From a02689b9052830edd73ff8e90072c33230b8503c Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 14:33:11 +1000 Subject: [PATCH 19/23] Revert tablelookup changes --- ZodiacFX/src/openflow/openflow_13.c | 37 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_13.c b/ZodiacFX/src/openflow/openflow_13.c index c40dad7..4d5fee7 100644 --- a/ZodiacFX/src/openflow/openflow_13.c +++ b/ZodiacFX/src/openflow/openflow_13.c @@ -222,18 +222,31 @@ void nnOF13_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) set_ip_checksum(p_uc_data, packet_size, fields.payload - p_uc_data); recalculate_ip_checksum = false; } + struct ofp13_action_output *act_output = act_hdr; - if (htonl(act_output->port) == OFPP13_CONTROLLER) + if (htonl(act_output->port) < OFPP13_MAX && htonl(act_output->port) != port) + { + int outport = (1<< (ntohl(act_output->port)-1)); + TRACE("openflow_13.c: Output to port %d (%d bytes)", ntohl(act_output->port), packet_size); + gmac_write(p_uc_data, packet_size, outport); + } else if (htonl(act_output->port) == OFPP13_IN_PORT) + { + int outport = (1<< (port-1)); + TRACE("openflow_13.c: Output to in_port %d (%d bytes)", port, packet_size); + gmac_write(p_uc_data, packet_size, outport); + } else if (htonl(act_output->port) == OFPP13_CONTROLLER) { int pisize = ntohs(act_output->max_len); if (pisize > packet_size) pisize = packet_size; TRACE("openflow_13.c: Output to controller (%d bytes)", packet_size); packet_in13(p_uc_data, pisize, port, OFPR_ACTION, i); - break; + } else if (htonl(act_output->port) == OFPP13_FLOOD || htonl(act_output->port) == OFPP13_ALL) + { + int outport = (15 - NativePortMatrix) - (1<<(port-1)); + if (htonl(act_output->port) == OFPP13_FLOOD) TRACE("openflow_13.c: Output to FLOOD (%d bytes)", packet_size); + if (htonl(act_output->port) == OFPP13_ALL) TRACE("openflow_13.c: Output to ALL (%d bytes)", packet_size); + gmac_write(p_uc_data, packet_size, outport); } - - gmac_write(p_uc_data, packet_size, htonl(act_output->port)); - } break; @@ -931,6 +944,7 @@ int multi_portdesc_reply13(uint8_t *buffer, struct ofp13_multipart_request *msg) j ++; } } + memcpy(reply->body, &phys_port[0],sizeof(phys_port)); return len; } @@ -2024,13 +2038,16 @@ void packet_out13(struct ofp_header *msg) struct ofp13_action_header *act_hdr = po->actions; if (ntohs(act_hdr->type) != OFPAT13_OUTPUT) return; struct ofp13_action_output *act_out = act_hdr; - TRACE("openflow_13.c: Packet out port 0x%X (%d bytes)", htonl(act_out->port), size); - if (htonl(act_out->port) == OFPP13_TABLE) + uint32_t outPort = htonl(act_out->port); + if (outPort == OFPP13_FLOOD) { - nnOF_tablelookup(ptr, &size, inPort); - return; + outPort = 7 - (1 << (inPort-1)); // Need to fix this, may also send out the Non-OpenFlow port + } else { + outPort = 1 << (outPort-1); + TRACE("openflow_13.c: Packet out FLOOD (%d bytes)", size); } - gmac_write(ptr, size, htonl(act_out->port)); + TRACE("openflow_13.c: Packet out port %d (%d bytes)", outPort, size); + gmac_write(ptr, size, outPort); return; } From 7162fb85682faae338aeefe872f5e5ba358f5dc9 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 14:39:06 +1000 Subject: [PATCH 20/23] Revert OF10 tablelookup changes --- ZodiacFX/src/openflow/openflow_10.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 46cfad4..81d399a 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -101,7 +101,7 @@ void nnOF10_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) uint16_t packet_size; struct packet_fields fields = {0}; packet_fields_parser(p_uc_data, &fields); - + memcpy(&packet_size, ul_size, 2); uint16_t eth_prot; memcpy(ð_prot, p_uc_data + 12, 2); @@ -121,6 +121,7 @@ void nnOF10_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) uint16_t tcpport; uint32_t ipadr; uint16_t vlantag = htons(0x8100); + int outport = 0; table_counters[0].lookup_count++; @@ -171,13 +172,30 @@ void nnOF10_tablelookup(uint8_t *p_uc_data, uint32_t *ul_size, int port) { case OFPAT10_OUTPUT: action_out = act_hdr; + if (ntohs(action_out->port) <= 255 && ntohs(action_out->port) != port) // physical port + { + outport = (1<< (ntohs(action_out->port)-1)); + gmac_write(p_uc_data, packet_size, outport); + } + + if (ntohs(action_out->port) == OFPP_IN_PORT) + { + outport = (1<< (port-1)); + gmac_write(p_uc_data, packet_size, outport); + } + + if (ntohs(action_out->port) == OFPP_ALL || ntohs(action_out->port) == OFPP_FLOOD) + { + outport = (15 - NativePortMatrix) - (1<<(port-1)); + gmac_write(p_uc_data, packet_size, outport); + } + if (ntohs(action_out->port) == OFPP_CONTROLLER) { int pisize = ntohs(action_out->max_len); if (pisize > packet_size) pisize = packet_size; packet_in(p_uc_data, pisize, port, OFPR_ACTION); } - gmac_write(p_uc_data, packet_size, ntohs(action_out->port)); break; case OFPAT10_SET_DL_SRC: From 132f8618d9c0e001df39a4f9de3bcbcf509b4405 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 15:04:44 +1000 Subject: [PATCH 21/23] Revert OF10 packet out changes --- ZodiacFX/src/openflow/openflow_10.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ZodiacFX/src/openflow/openflow_10.c b/ZodiacFX/src/openflow/openflow_10.c index 81d399a..9502836 100644 --- a/ZodiacFX/src/openflow/openflow_10.c +++ b/ZodiacFX/src/openflow/openflow_10.c @@ -773,14 +773,23 @@ void packet_out(struct ofp_header *msg) int size = NTOHS(po->header.length) - ((sizeof(struct ofp_packet_out) + NTOHS(po->actions_len))); uint16_t *eport; eport = ptr - 4; - TRACE("openflow_10.c: Packet out port 0x%X (%d bytes)", NTOHS(*eport), size); - - if (NTOHS(*eport) == OFPP_TABLE) + int outPort = NTOHS(*eport); + int inPort = NTOHS(*iport); + + if (outPort == OFPP_TABLE) { - nnOF_tablelookup(ptr, &size, NTOHS(*iport)); + nnOF_tablelookup(ptr, &size, inPort); return; } - gmac_write(ptr, size, NTOHS(*eport)); + + if (outPort == OFPP_FLOOD || outPort == OFPP13_ALL) + { + outPort = (15 - NativePortMatrix) - (1<<(inPort-1)); + } else + { + outPort = 1 << (outPort-1); + } + gmac_write(ptr, size, outPort); return; } From d68254e54965e50af4821a3d99984b1e9b6a4337 Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 16:38:18 +1000 Subject: [PATCH 22/23] Modify ethernet buffer declaration --- ZodiacFX/src/switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZodiacFX/src/switch.c b/ZodiacFX/src/switch.c index caf19df..533262d 100644 --- a/ZodiacFX/src/switch.c +++ b/ZodiacFX/src/switch.c @@ -56,7 +56,7 @@ struct ofp10_port_stats phys10_port_stats[TOTAL_PORTS]; struct ofp13_port_stats phys13_port_stats[TOTAL_PORTS]; uint8_t port_status[TOTAL_PORTS]; uint8_t last_port_status[TOTAL_PORTS]; -uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; +static volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]; uint8_t stats_rr = 0; /* GMAC HW configurations */ From c5be33ed2e5445c7574c95ef7e8fe73379303bfd Mon Sep 17 00:00:00 2001 From: Kristopher Chen Date: Tue, 23 May 2017 17:01:04 +1000 Subject: [PATCH 23/23] Remove stacking source from project --- ZodiacFX/ZodiacFX.cproj | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ZodiacFX/ZodiacFX.cproj b/ZodiacFX/ZodiacFX.cproj index ab4e3bd..bb1eeff 100644 --- a/ZodiacFX/ZodiacFX.cproj +++ b/ZodiacFX/ZodiacFX.cproj @@ -720,12 +720,6 @@ compile - - compile - - - compile - compile