Commit 69f53c93 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

Merge branch 'snmp-support' into proposed_master

parents 699fb5da da0dcab6
......@@ -136,6 +136,23 @@ config SYSLOG
The user (or init script) must use "syslog <ipaddr> <macaddr>"
to enable it. The special "off" ipaddr disables syslog.
config SNMP
depends on IP
default y
boolean "Mini SNMP responder"
config SNMP_SET
depends on SNMP
default y
boolean "Add SET support to the Mini SNMP responder"
help
This option enables support for SET requests for Mini SNMP responder
config SNMP_HW_TYPE
depends on SNMP
default "spec"
string "Hardware type reported by SNMP"
config BUILD_INIT
depends on WR_NODE
default n
......@@ -360,6 +377,12 @@ config WRC_VERBOSE
help
This enables some more diagnostic messages. Normally off.
config SNMP_VERBOSE
depends on DEVELOPER && SNMP
boolean "More verbose messages in SNMP"
help
This enables some more diagnostic messages. Normally off.
config FAKE_TEMPERATURES
depends on DEVELOPER
boolean "Offer an array of 3 fake temperatures, for testing"
......
......@@ -110,6 +110,12 @@ OUTPUT-$(CONFIG_WR_SWITCH) = rt_cpu
OUTPUT := $(OUTPUT-y)
GIT_VER = $(shell git describe --always --dirty | sed 's;^wr-switch-sw-;;')
GIT_USR = $(shell git config --get-all user.name)
# if user.name is not available from git use user@hostname
ifeq ($(GIT_USR),)
GIT_USR = $(shell whoami)@$(shell hostname)
endif
all: tools $(OUTPUT).elf $(arch-files-y)
......@@ -140,7 +146,7 @@ sdb-lib/libsdbfs.a:
$(MAKE) -C sdb-lib
$(OUTPUT).elf: $(LDS-y) $(AUTOCONF) gitmodules $(OUTPUT).o config.o
$(CC) $(CFLAGS) -D__GIT_VER__="\"$(GIT_VER)\"" -c revision.c
$(CC) $(CFLAGS) -D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\"" -c revision.c
${CC} -o $@ revision.o config.o $(OUTPUT).o $(LDFLAGS)
${OBJDUMP} -d $(OUTPUT).elf > $(OUTPUT)_disasm.S
$(SIZE) $@
......
#
# Automatically generated make config: don't edit
#
# CONFIG_WR_SWITCH is not set
CONFIG_WR_NODE=y
CONFIG_PRINT_BUFSIZE=128
CONFIG_PRINTF_XINT=y
CONFIG_RAMSIZE=131072
CONFIG_TEMP_POLL_INTERVAL=15
CONFIG_VLAN_NR=0
CONFIG_VLAN_1_FOR_CLASS7=0
CONFIG_VLAN_2_FOR_CLASS7=0
CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_LM32=y
CONFIG_EMBEDDED_NODE=y
# CONFIG_WR_NODE_PCS16 is not set
CONFIG_STACKSIZE=2048
CONFIG_PPSI=y
CONFIG_UART=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=0
CONFIG_IP=y
# CONFIG_CMD_CONFIG is not set
# CONFIG_SYSLOG is not set
CONFIG_SNMP=y
# CONFIG_SNMP_SET is not set
CONFIG_SNMP_HW_TYPE="spec"
# CONFIG_BUILD_INIT is not set
CONFIG_INIT_COMMAND=""
CONFIG_HAS_BUILD_INIT=0
CONFIG_HAS_FLASH_INIT=1
CONFIG_FLASH_INIT=y
#
# wrpc-sw is tainted if you change the following options
#
# CONFIG_DEVELOPER is not set
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
CONFIG_VLAN_ARRAY_SIZE=1
#
# Automatically generated make config: don't edit
#
# CONFIG_WR_SWITCH is not set
CONFIG_WR_NODE=y
CONFIG_PRINT_BUFSIZE=128
CONFIG_PRINTF_XINT=y
CONFIG_RAMSIZE=131072
CONFIG_TEMP_POLL_INTERVAL=15
# CONFIG_PLL_VERBOSE is not set
# CONFIG_PFILTER_VERBOSE is not set
# CONFIG_WRC_VERBOSE is not set
# CONFIG_VLAN is not set
CONFIG_VLAN_NR=0
CONFIG_VLAN_1_FOR_CLASS7=0
CONFIG_VLAN_2_FOR_CLASS7=0
CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_LM32=y
CONFIG_EMBEDDED_NODE=y
# CONFIG_WR_NODE_PCS16 is not set
CONFIG_STACKSIZE=2048
CONFIG_PPSI=y
CONFIG_UART=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=0
CONFIG_IP=y
# CONFIG_CMD_CONFIG is not set
# CONFIG_SYSLOG is not set
CONFIG_SNMP=y
CONFIG_SNMP_SET=y
CONFIG_SNMP_HW_TYPE="spec"
# CONFIG_BUILD_INIT is not set
CONFIG_INIT_COMMAND=""
CONFIG_HAS_BUILD_INIT=0
CONFIG_HAS_FLASH_INIT=1
CONFIG_FLASH_INIT=y
#
# wrpc-sw is tainted if you change the following options
#
CONFIG_DEVELOPER=y
# CONFIG_CMD_LL is not set
# CONFIG_CHECK_RESET is not set
# CONFIG_SPLL_FIFO_LOG is not set
# CONFIG_PRINTF_FULL is not set
# CONFIG_PRINTF_MINI is not set
# CONFIG_PRINTF_NONE is not set
# CONFIG_DETERMINISTIC_BINARY is not set
# CONFIG_UART_SW is not set
# CONFIG_NET_VERBOSE is not set
CONFIG_SNMP_VERBOSE=y
CONFIG_FAKE_TEMPERATURES=y
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
# CONFIG_LATENCY_PROBE is not set
CONFIG_VLAN_ARRAY_SIZE=1
......@@ -57,6 +57,10 @@
* ------------------------------------------------
*/
#define SFP_DB_EMPTY 0xff
static uint8_t sfpcount = SFP_DB_EMPTY;
uint8_t has_eeprom = 0;
static int i2cif, i2c_addr; /* globals, using the names we always used */
......@@ -137,7 +141,7 @@ static int eeprom_write(uint8_t i2cif, uint8_t i2c_addr, uint32_t offset,
int32_t storage_sfpdb_erase(void)
{
uint8_t sfpcount = 0;
sfpcount = 0;
//just a dummy function that writes '0' to sfp count field of the SFP DB
if (eeprom_write(i2cif, i2c_addr, EE_BASE_SFP, &sfpcount,
......@@ -147,28 +151,44 @@ int32_t storage_sfpdb_erase(void)
return sfpcount;
}
int storage_get_sfp(struct s_sfpinfo * sfp,
uint8_t add, uint8_t pos)
static uint8_t sfp_chksum(uint8_t *ptr)
{
int i;
uint8_t chksum = 0;
/* '-1' because we do not include chksum in computation */
for (i = 0; i < sizeof(struct s_sfpinfo) - 1; ++i)
chksum = (uint8_t) ((uint16_t) chksum + *(ptr++)) & 0xff;
return chksum;
}
int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
{
static uint8_t sfpcount = 0;
uint8_t i, chksum = 0;
uint8_t *ptr;
uint8_t i;
struct s_sfpinfo dbsfp;
if (pos >= SFPS_MAX)
return EE_RET_POSERR; //position in database outside the range
if (pos >= SFPS_MAX) {
/* position in database outside the range */
return EE_RET_POSERR;
}
//read how many SFPs are in the database, but only in the first call (pos==0)
if (!pos
/* Read how many SFPs are in the database, but only in the first call
*/
if (sfpcount == SFP_DB_EMPTY
&& eeprom_read(i2cif, i2c_addr, EE_BASE_SFP, &sfpcount,
sizeof(sfpcount)) != sizeof(sfpcount))
return EE_RET_I2CERR;
if (add && sfpcount == SFPS_MAX) //no more space in the database to add new SFPs
return EE_RET_DBFULL;
else if (!pos && !add && sfpcount == 0) //there are no SFPs in the database to read
return sfpcount;
/* for not written flash set sfpcount to 0 */
if (sfpcount == SFP_DB_EMPTY)
sfpcount = 0;
if (oper == SFP_GET) {
if (sfpcount == 0) {
/* There are no SFPs in the database to read */
return 0;
}
if (!add) {
if (eeprom_read(i2cif, i2c_addr,
EE_BASE_SFP + sizeof(sfpcount)
+ pos * sizeof(struct s_sfpinfo),
......@@ -176,47 +196,58 @@ int storage_get_sfp(struct s_sfpinfo * sfp,
!= sizeof(struct s_sfpinfo) )
return EE_RET_I2CERR;
ptr = (uint8_t *) sfp;
for (i = 0; i < sizeof(struct s_sfpinfo) - 1; ++i) //'-1' because we do not include chksum in computation
chksum =
(uint8_t) ((uint16_t) chksum + *(ptr++)) & 0xff;
if (chksum != sfp->chksum)
if (sfp_chksum((uint8_t *)sfp) != sfp->chksum)
return EE_RET_CORRPT;
} else {
/*count checksum */
ptr = (uint8_t *) sfp;
for (i = 0; i < sizeof(struct s_sfpinfo) - 1; ++i) //'-1' because we do not include chksum in computation
chksum =
(uint8_t) ((uint16_t) chksum + *(ptr++)) & 0xff;
sfp->chksum = chksum;
/*add SFP at the end of DB */
}
if (oper == SFP_ADD) {
for (i = 0; i < sfpcount; i++) {
if (eeprom_read(i2cif, i2c_addr,
EE_BASE_SFP + sizeof(sfpcount)
+ i * sizeof(struct s_sfpinfo),
(uint8_t *)&dbsfp, sizeof(struct s_sfpinfo))
!= sizeof(struct s_sfpinfo))
return EE_RET_I2CERR;
if (!strncmp(dbsfp.pn, sfp->pn, 16)) { /* sfp matched */
pp_printf("Update existing SFP entry\n");
break;
}
}
if (i >= SFPS_MAX) { /* database is full */
return EE_RET_DBFULL;
}
/* Count checksum */
sfp->chksum = sfp_chksum((uint8_t *)sfp);
/* Add an entry at the given pos in the DB */
eeprom_write(i2cif, i2c_addr,
EE_BASE_SFP + sizeof(sfpcount)
+ sfpcount * sizeof(struct s_sfpinfo),
+ i * sizeof(struct s_sfpinfo),
(uint8_t *) sfp, sizeof(struct s_sfpinfo));
if (i >= sfpcount) {
pp_printf("Adding new SFP entry\n");
/* We're adding a new entry, update sfpcount */
sfpcount++;
eeprom_write(i2cif, i2c_addr, EE_BASE_SFP, &sfpcount,
sizeof(sfpcount));
}
}
return sfpcount;
}
int storage_match_sfp(struct s_sfpinfo * sfp)
{
uint8_t sfpcount = 1;
int8_t i, temp;
int8_t i;
int sfp_cnt = 1;
struct s_sfpinfo dbsfp;
for (i = 0; i < sfpcount; ++i) {
temp = storage_get_sfp(&dbsfp, 0, i);
if (!i) {
sfpcount = temp; //only in first round valid sfpcount is returned from eeprom_get_sfp
if (sfpcount == 0 || sfpcount == 0xFF)
return 0;
else if (sfpcount < 0)
return sfpcount;
}
for (i = 0; i < sfp_cnt; ++i) {
sfp_cnt = storage_get_sfp(&dbsfp, SFP_GET, i);
if (sfp_cnt <= 0)
return sfp_cnt;
if (!strncmp(dbsfp.pn, sfp->pn, 16)) {
sfp->dTx = dbsfp.dTx;
sfp->dRx = dbsfp.dRx;
......
......@@ -80,6 +80,11 @@ int flash_write(uint32_t addr, uint8_t *buf, int count)
}
bbspi_transfer(1,0);
/* make sure the write is complete */
while (flash_rsr() & 0x01) {
/* do nothing */
}
return count;
}
......
......@@ -52,16 +52,7 @@
static volatile uint32_t dma_tx_buf[MINIC_DMA_TX_BUF_SIZE / 4];
static volatile uint32_t dma_rx_buf[MINIC_DMA_RX_BUF_SIZE / 4];
struct wr_minic {
volatile uint32_t *rx_head, *rx_base;
uint32_t rx_avail, rx_size;
volatile uint32_t *tx_head, *tx_base;
uint32_t tx_avail, tx_size;
int tx_count, rx_count;
};
static struct wr_minic minic;
struct wr_minic minic;
static inline void minic_writel(uint32_t reg, uint32_t data)
{
......
......@@ -7,7 +7,6 @@
*
* Released according to the GNU GPL, version 2 or any later version.
*/
//#include <string.h>
#include <wrc.h>
#include <w1.h>
#include <storage.h>
......@@ -166,7 +165,7 @@ static void storage_sdb_list(struct sdbfs *fs)
{
struct sdb_device *d;
int new = 1;
while ( (d = sdbfs_scan(fs, new)) != NULL) {
while ((d = sdbfs_scan(fs, new)) != NULL) {
d->sdb_component.product.record_type = '\0';
pp_printf("file 0x%08x @ %4i, name %s\n",
(int)(d->sdb_component.product.device_id),
......@@ -196,12 +195,12 @@ void storage_init(int chosen_i2cif, int chosen_i2c_addr)
uint32_t magic = 0;
static unsigned entry_points_eeprom[] = {0, 64, 128, 256, 512, 1024};
static unsigned entry_points_flash[] = {
0x000000, // flash base
0x100, // second page in flash
0x200, // IPMI with MultiRecord
0x300, // IPMI with larger MultiRecord
0x170000, // after first FPGA bitstream
0x2e0000}; // after MultiBoot bitstream
0x000000, /* flash base */
0x100, /* second page in flash */
0x200, /* IPMI with MultiRecord */
0x300, /* IPMI with larger MultiRecord */
0x170000, /* after first FPGA bitstream */
0x2e0000}; /* after MultiBoot bitstream */
int i, ret;
/*
......@@ -209,7 +208,7 @@ void storage_init(int chosen_i2cif, int chosen_i2c_addr)
*/
for (i = 0; i < ARRAY_SIZE(entry_points_flash); i++) {
flash_read(entry_points_flash[i], (void *)&magic, sizeof(magic));
if(magic == SDB_MAGIC)
if (magic == SDB_MAGIC)
break;
}
if (magic == SDB_MAGIC) {
......@@ -292,7 +291,7 @@ found_exit:
* setting if no sdbfs is there, but CONFIG_SDB_STORAGE depends on
* CONFIG_W1 anyways.
*/
int get_persistent_mac(uint8_t portnum, uint8_t * mac)
int get_persistent_mac(uint8_t portnum, uint8_t *mac)
{
int ret;
int i, class;
......@@ -310,7 +309,7 @@ int get_persistent_mac(uint8_t portnum, uint8_t * mac)
ret = sdbfs_fread(&wrc_sdb, 0, mac, 6);
sdbfs_close(&wrc_sdb);
if(ret < 0)
if (ret < 0)
pp_printf("%s: SDB error\n", __func__);
if (mac[0] == 0xff ||
(mac[0] | mac[1] | mac[2] | mac[3] | mac[4] | mac[5]) == 0) {
......@@ -340,7 +339,7 @@ int get_persistent_mac(uint8_t portnum, uint8_t * mac)
return 0;
}
int set_persistent_mac(uint8_t portnum, uint8_t * mac)
int set_persistent_mac(uint8_t portnum, uint8_t *mac)
{
int ret;
......@@ -383,7 +382,7 @@ int32_t storage_sfpdb_erase(void)
if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_SFP) < 0)
return -1;
ret = sdbfs_ferase(&wrc_sdb, 0, wrc_sdb.f_len);
if(ret == wrc_sdb.f_len)
if (ret == wrc_sdb.f_len)
ret = 1;
sdbfs_close(&wrc_sdb);
return ret == 1 ? 0 : -1;
......@@ -395,49 +394,57 @@ static int sfp_valid(struct s_sfpinfo *sfp)
{
int i;
for(i=0; i<SFP_PN_LEN; ++i) {
if(sfp->pn[i] == 0xff)
for (i = 0; i < SFP_PN_LEN; ++i) {
if (sfp->pn[i] == 0xff)
return 0;
}
return 1;
}
int storage_get_sfp(struct s_sfpinfo * sfp,
uint8_t add, uint8_t pos)
static int sfp_entry(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
{
static uint8_t sfpcount = 0;
struct s_sfpinfo tempsfp;
int ret = -1;
uint8_t i, chksum = 0;
uint8_t *ptr;
int sdb_offset;
if (pos >= SFPS_MAX)
return EE_RET_POSERR; //position outside the range
return EE_RET_POSERR; /* position outside the range */
if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_SFP) < 0)
return -1;
//read how many SFPs are in the database, but only in the first call
if(!pos) {
/* Read how many SFPs are in the database, but only in the first
* call */
if (!pos) {
sfpcount = 0;
while (sdbfs_fread(&wrc_sdb, sizeof(sfpcount) +
sfpcount*sizeof(tempsfp), &tempsfp,
sdb_offset = sizeof(sfpcount);
while (sdbfs_fread(&wrc_sdb, sdb_offset, &tempsfp,
sizeof(tempsfp)) == sizeof(tempsfp)) {
if(!sfp_valid(&tempsfp))
if (!sfp_valid(&tempsfp))
break;
sfpcount++;
sdb_offset = sizeof(sfpcount) + sfpcount * sizeof(tempsfp);
}
}
if (add && sfpcount == SFPS_MAX) //no more space to add new SFPs
return EE_RET_DBFULL;
if (!pos && !add && sfpcount == 0) // no SFPs in the database
return 0;
if ((oper == SFP_ADD) && (sfpcount == SFPS_MAX)) {
/* no more space to add new SFPs */
ret = EE_RET_DBFULL;
goto out;
}
if (!add) {
if (sdbfs_fread(&wrc_sdb, sizeof(sfpcount) + pos * sizeof(*sfp),
sfp, sizeof(*sfp))
if (!pos && (oper == SFP_GET) && sfpcount == 0) {
/* no SFPs in the database */
ret = 0;
goto out;
}
if (oper == SFP_GET) {
sdb_offset = sizeof(sfpcount) + pos * sizeof(*sfp);
if (sdbfs_fread(&wrc_sdb, sdb_offset, sfp, sizeof(*sfp))
!= sizeof(*sfp))
goto out;
......@@ -449,46 +456,99 @@ int storage_get_sfp(struct s_sfpinfo * sfp,
pp_printf("sfp: corrupted checksum\n");
goto out;
}
} else {
/*count checksum */
}
if (oper == SFP_ADD) {
/* count checksum */
ptr = (uint8_t *)sfp;
/* use sizeof() - 1 because we don't include checksum */
for (i = 0; i < sizeof(struct s_sfpinfo) - 1; ++i)
chksum = chksum + *(ptr++);
sfp->chksum = chksum;
/* add SFP at the end of DB */
if (sdbfs_fwrite(&wrc_sdb, sizeof(sfpcount)
+ sfpcount * sizeof(*sfp), sfp, sizeof(*sfp))
!= sizeof(*sfp))
sdb_offset = sizeof(sfpcount) + sfpcount * sizeof(*sfp);
if (sdbfs_fwrite(&wrc_sdb, sdb_offset, sfp, sizeof(*sfp))
!= sizeof(*sfp)) {
goto out;
}
sfpcount++;
if (sdbfs_fwrite(&wrc_sdb, 0, &sfpcount, sizeof(sfpcount))
!= sizeof(sfpcount))
goto out;
}
ret = sfpcount;
out:
sdbfs_close(&wrc_sdb);
return ret;
return 0;
}
int storage_match_sfp(struct s_sfpinfo * sfp)
static int storage_update_sfp(struct s_sfpinfo *sfp)
{
int sfpcount = 1;
int temp;
int8_t i;
struct s_sfpinfo sfp_db[SFPS_MAX];
struct s_sfpinfo *dbsfp;
/* copy entries from flash to the memory, update entry if matched */
for (i = 0; i < sfpcount; ++i) {
dbsfp = &sfp_db[i];
sfpcount = sfp_entry(dbsfp, SFP_GET, i);
if (sfpcount <= 0)
return sfpcount;
if (!strncmp(dbsfp->pn, sfp->pn, 16)) {
/* update matched entry */
dbsfp->dTx = sfp->dTx;
dbsfp->dRx = sfp->dRx;
dbsfp->alpha = sfp->alpha;
}
}
/* erase entire database */
if (storage_sfpdb_erase() == EE_RET_I2CERR) {
pp_printf("Could not erase DB\n");
return -1;
}
/* add all SFPs */
for (i = 0; i < sfpcount; ++i) {
dbsfp = &sfp_db[i];
temp = sfp_entry(dbsfp, SFP_ADD, 0);
if (temp < 0) {
/* if error, return it */
return temp;
}
}
return i;
}
int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
{
struct s_sfpinfo tmp_sfp;
if (oper == SFP_GET) {
/* Get SFP entry */
return sfp_entry(sfp, SFP_GET, pos);
}
/* storage_match_sfp replaces content of parameter, so do the copy
* first */
tmp_sfp = *sfp;
if (!storage_match_sfp(&tmp_sfp)) { /* add a new sfp entry */
pp_printf("Adding new SFP entry\n");
return sfp_entry(sfp, SFP_ADD, 0);
}
pp_printf("Update existing SFP entry\n");
return storage_update_sfp(sfp);
}
int storage_match_sfp(struct s_sfpinfo *sfp)
{
uint8_t sfpcount = 1;
int8_t i, temp;
int8_t i;
struct s_sfpinfo dbsfp;
for (i = 0; i < sfpcount; ++i) {
temp = storage_get_sfp(&dbsfp, 0, i);
if (!i) {
// first round: valid sfpcount is returned
sfpcount = temp;
if (sfpcount == 0 || sfpcount == 0xFF)
return 0;
else if (sfpcount < 0)
sfpcount = sfp_entry(&dbsfp, SFP_GET, i);
if (sfpcount <= 0)
return sfpcount;
}
if (!strncmp(dbsfp.pn, sfp->pn, 16)) {
sfp->dTx = dbsfp.dTx;
sfp->dRx = dbsfp.dRx;
......@@ -504,8 +564,7 @@ int storage_match_sfp(struct s_sfpinfo * sfp)
* Phase transition ("calibration" file)
*/
#define VALIDITY_BIT 0x80000000
int storage_phtrans(uint32_t * valp,
uint8_t write)
int storage_phtrans(uint32_t *valp, uint8_t write)
{
int ret = -1;
uint32_t value;
......@@ -551,7 +610,7 @@ int storage_init_erase(void)
if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_INIT) < 0)
return -1;
ret = sdbfs_ferase(&wrc_sdb, 0, wrc_sdb.f_len);
if(ret == wrc_sdb.f_len)
if (ret == wrc_sdb.f_len)
ret = 1;
sdbfs_close(&wrc_sdb);
return ret == 1 ? 0 : -1;
......@@ -576,7 +635,7 @@ int storage_init_add(const char *args[])
while (sdbfs_fread(&wrc_sdb, sizeof(used)+used, &byte, 1) == 1) {
if (byte == 0xff)
break;
used ++;
used++;
}
if (used > 256 /* 0xffff or wrong */)
......@@ -589,7 +648,7 @@ int storage_init_add(const char *args[])
(void *)args[i], len) != len)
goto out;
used += len;
if(args[i+1] != NULL) /* next one is another word of the same command */
if (args[i+1] != NULL) /* next one is another word of the same command */
separator = ' ';
else /* no more words, end command with '\n' */
separator = '\n';
......@@ -627,13 +686,13 @@ int storage_init_show(void)
do {
if (sdbfs_fread(&wrc_sdb, sizeof(used) + used, &byte, 1) != 1)
goto out;
if(byte != 0xff) {
if (byte != 0xff) {
pp_printf("%c", byte);
used++;
}
} while(byte != 0xff);
} while (byte != 0xff);
if(used == 0)
if (used == 0)
pp_printf("Empty init script...\n");
ret = 0;
out:
......
......@@ -10,10 +10,21 @@
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include <errno.h>
#include "syscon.h"
#include "i2c.h"
#include "sfp.h"
#include "storage.h"
/* Calibration data (from EEPROM if available) */
int32_t sfp_alpha = 73622176; /* default values if could not read EEPROM */
int32_t sfp_deltaTx = 0;
int32_t sfp_deltaRx = 0;
int32_t sfp_in_db = 0;
char sfp_pn[SFP_PN_LEN];
int sfp_present(void)
{
......@@ -52,3 +63,27 @@ int sfp_read_part_id(char *part_id)
return -1;
}
int sfp_match(void)
{
struct s_sfpinfo sfp;
sfp_pn[0] = '\0';
if (!sfp_present()) {
return -ENODEV;
}
if (sfp_read_part_id(sfp_pn)) {
return -EIO;
}
strncpy(sfp.pn, sfp_pn, SFP_PN_LEN);
if (storage_match_sfp(&sfp) == 0) {
sfp_in_db = SFP_NOT_MATCHED;
return -ENXIO;
}
sfp_deltaTx = sfp.dTx;
sfp_deltaRx = sfp.dRx;
sfp_alpha = sfp.alpha;
sfp_in_db = SFP_MATCHED;
return 0;
}
This diff is collapsed.
......@@ -33,6 +33,17 @@ struct wr_ethhdr_vlan {
uint16_t ethtype_2;
};
struct wr_minic {
volatile uint32_t *rx_head, *rx_base;
uint32_t rx_avail, rx_size;
volatile uint32_t *tx_head, *tx_base;
uint32_t tx_avail, tx_size;
int tx_count, rx_count;
};
extern struct wr_minic minic;
int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size,
struct hw_timestamp *hwts);
int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t * payload, uint32_t size,
......
......@@ -4,5 +4,6 @@
extern const char *build_revision;
extern const char *build_date;
extern const char *build_time;
extern const char *build_by;
#endif /* __REVISION_H__ */
......@@ -9,10 +9,27 @@
#include <stdint.h>
#define SFP_PN_LEN 16
#define SFP_NOT_MATCHED 1
#define SFP_MATCHED 2
#define SFP_GET 0
#define SFP_ADD 1
extern char sfp_pn[SFP_PN_LEN];
extern int32_t sfp_in_db;
extern int32_t sfp_alpha;
extern int32_t sfp_deltaTx;
extern int32_t sfp_deltaRx;
/* Returns 1 if there's a SFP transceiver inserted in the socket. */
int sfp_present(void);
/* Reads the part ID of the SFP from its configuration EEPROM */
int sfp_read_part_id(char *part_id);
/* Match plugged SFP with a DB entry */
int sfp_match(void);
#endif
......@@ -9,21 +9,43 @@
#ifndef __STORAGE_H
#define __STORAGE_H
#include "sfp.h"
#define SFP_SECTION_PATTERN 0xdeadbeef
#if defined CONFIG_LEGACY_EEPROM
#define EE_BASE_CAL (4 * 1024)
#define EE_BASE_SFP (4 * 1024 + 4)
/* Limit SFPs to 3, see comments below why. */
#define SFPS_MAX 3
/* The definition of EE_BASE_INIT below is wrong! But kept for backward
* compatibility. */
#define EE_BASE_INIT (4 * 1024 + 4 * 29)
/* It should be:
* #define EE_BASE_INIT (EE_BASE_SFP + sizeof(sfpcount) + \
* SFPS_MAX * sizeof(struct s_sfpinfo))
* The used definition define the start of the init script 5 bytes
* (sizeof(sfpcount) + sizeof(t24p)) before the end of SFP database.
* To make the init script working during the update of old versions of wrpc
* SFPS_MAX is limited to 3. Adding the 4th SFP will corrupt the init script
* anyway.
* If someone needs to have 4 SFPs in the database SFPS_MAX can be set to 4 and
* the proper define should be used.
* SDB is not affected by this bug.
*/
#endif
#if defined CONFIG_SDB_STORAGE
#define SFPS_MAX 4
#define SFP_PN_LEN 16
#define EE_BASE_CAL 4*1024
#define EE_BASE_SFP 4*1024+4
#define EE_BASE_INIT 4*1024+SFPS_MAX*29
#endif
#define EE_RET_I2CERR -1
#define EE_RET_DBFULL -2
#define EE_RET_CORRPT -3
#define EE_RET_POSERR -4
extern int32_t sfp_alpha;
extern int32_t sfp_deltaTx;
extern int32_t sfp_deltaRx;
extern uint32_t cal_phase_transition;
extern uint8_t has_eeprom;
......
......@@ -25,6 +25,12 @@
#define WRC_IS_VERBOSE 0
#endif
#ifdef CONFIG_SNMP_VERBOSE
#define SNMP_IS_VERBOSE 1
#else
#define SNMP_IS_VERBOSE 0
#endif
#define pll_verbose(...) \
({if (PLL_IS_VERBOSE) __debug_printf(__VA_ARGS__);})
......@@ -37,6 +43,9 @@
#define net_verbose(...) \
({if (NET_IS_VERBOSE) __debug_printf(__VA_ARGS__);})
#define snmp_verbose(...) \
({if (SNMP_IS_VERBOSE) __debug_printf(__VA_ARGS__);})
#ifdef CONFIG_HOST_PROCESS
#define IS_HOST_PROCESS 1
......
......@@ -21,6 +21,13 @@
#define vprintf pp_vprintf
#define sprintf pp_sprintf
#ifndef min
#define min(a, b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
#endif
#undef offsetof
#define offsetof(TYPE, MEMBER) ((long) &((TYPE *)0)->MEMBER)
#undef ARRAY_SIZE
......
This diff is collapsed.
......@@ -9,3 +9,4 @@ obj-$(CONFIG_WR_NODE) += lib/net.o
obj-$(CONFIG_IP) += lib/ipv4.o lib/arp.o lib/icmp.o lib/udp.o lib/bootp.o
obj-$(CONFIG_SYSLOG) += lib/syslog.o
obj-$(CONFIG_LATENCY_PROBE) += lib/latency.o
obj-$(CONFIG_SNMP) += lib/snmp.o
......@@ -24,8 +24,6 @@
#include "softpll_ng.h"
#include "ipv4.h"
#define min(x,y) ((x) < (y) ? (x) : (y))
static struct wrpc_socket *socks[NET_MAX_SOCKETS];
//#define net_verbose pp_printf
......
This diff is collapsed.
......@@ -13,6 +13,7 @@ const char *build_revision = stats.commit_id;
const char *build_date = stats.build_date;
const char *build_time = stats.build_time;
const char *build_by = stats.build_by;
/*
* We export softpll internal status to the ARM cpu, for SNMP. Thus,
* we place this structure at a known address in the linker script
......@@ -22,9 +23,12 @@ struct spll_stats stats __attribute__((section(".stats"))) = {
.ver = SPLL_STATS_VER,
#ifdef CONFIG_DETERMINISTIC_BINARY
.build_date = "",
.build_time = "",
.build_by = "",
#else
.build_date = __DATE__,
.build_time = __TIME__,
.build_by = __GIT_USR__,
#endif
.commit_id = __GIT_VER__,
};
......@@ -8,17 +8,17 @@
* Released according to the GNU GPL, version 2 or any later version.
*/
/* Command: sfp
Arguments: subcommand [subcommand-specific args]
Description: SFP detection/database manipulation.
Subcommands:
add vendor_type delta_tx delta_rx alpha - adds an SFP to the database, with given alpha/delta_rx/delta_rx values
show - shows the SFP database
match - tries to get calibration parameters from DB for a detected SFP
erase - cleans the SFP database
detect - detects the transceiver type
*/
* Arguments: subcommand [subcommand-specific args]
*
* Description: SFP detection/database manipulation.
* Subcommands:
* add <product_number> <delta_tx> <delta_rx> <alpha> - adds an SFP to
* the database, with given alpha/delta_rx/delta_tx values
* show - shows the SFP database
* match - detects the transceiver type and tries to get calibration parameters
* from DB for a detected SFP
* erase - cleans the SFP database
*/
#include <string.h>
#include <stdlib.h>
......@@ -34,87 +34,90 @@
static int cmd_sfp(const char *args[])
{
int8_t sfpcount = 1, i, temp;
int8_t sfpcount = 1, i, temp, ret;
struct s_sfpinfo sfp;
static char pn[SFP_PN_LEN + 1] = "\0";
if (args[0] && !strcasecmp(args[0], "detect")) {
if (!sfp_present())
pp_printf("No SFP.\n");
else
sfp_read_part_id(pn);
pn[16] = 0;
pp_printf("%s\n", pn);
return 0;
if (!args[0]) {
pp_printf("Wrong parameter\n");
return -EINVAL;
}
// else if (!strcasecmp(args[0], "i2cscan"))
// {
// mi2c_scan(WRPC_FMC_I2C);
// return 0;
// }
else if (!strcasecmp(args[0], "erase")) {
if (storage_sfpdb_erase() ==
EE_RET_I2CERR)
if (!strcasecmp(args[0], "erase")) {
if (storage_sfpdb_erase() == EE_RET_I2CERR) {
pp_printf("Could not erase DB\n");
return -EIO;
}
return 0;
} else if (args[4] && !strcasecmp(args[0], "add")) {
if (strlen(args[1]) > 16)
temp = 16;
else
temp = strlen(args[1]);
temp = strnlen(args[1], SFP_PN_LEN);
for (i = 0; i < temp; ++i)
sfp.pn[i] = args[1][i];
while (i < 16)
while (i < SFP_PN_LEN)
sfp.pn[i++] = ' '; //padding
sfp.dTx = atoi(args[2]);
sfp.dRx = atoi(args[3]);
sfp.alpha = atoi(args[4]);
temp = storage_get_sfp(&sfp, 1, 0);
if (temp == EE_RET_DBFULL)
temp = storage_get_sfp(&sfp, SFP_ADD, 0);
if (temp == EE_RET_DBFULL) {
pp_printf("SFP DB is full\n");
else if (temp == EE_RET_I2CERR)
return -ENOSPC;
} else if (temp == EE_RET_I2CERR) {
pp_printf("I2C error\n");
else
return -EIO;
} else if (temp < 0) {
pp_printf("SFP database error (%d)\n", temp);
return -EFAULT;
}
pp_printf("%d SFPs in DB\n", temp);
} else if (args[0] && !strcasecmp(args[0], "show")) {
for (i = 0; i < sfpcount; ++i) {
temp = storage_get_sfp(&sfp, 0, i);
if (!i) {
sfpcount = temp; //only in first round valid sfpcount is returned from storage_get_sfp
if (sfpcount == 0 || sfpcount == 0xFF) {
pp_printf("SFP database empty...\n");
return 0;
} else if (sfpcount == -1) {
pp_printf("SFP database corrupted...\n");
} else if (!strcasecmp(args[0], "show")) {
for (i = 0; i < sfpcount; ++i) {
sfpcount = storage_get_sfp(&sfp, SFP_GET, i);
if (sfpcount == 0) {
pp_printf("SFP database empty\n");
return 0;
}
} else if (sfpcount < 0) {
pp_printf("SFP database error (%d)\n",
sfpcount);
return -EFAULT;
}
pp_printf("%d: PN:", i + 1);
for (temp = 0; temp < 16; ++temp)
for (temp = 0; temp < SFP_PN_LEN; ++temp)
pp_printf("%c", sfp.pn[temp]);
pp_printf(" dTx: %d, dRx: %d, alpha: %d\n", sfp.dTx,
pp_printf(" dTx: %8d dRx: %8d alpha: %8d\n", sfp.dTx,
sfp.dRx, sfp.alpha);
}
} else if (args[0] && !strcasecmp(args[0], "match")) {
if (pn[0] == '\0') {
pp_printf("Run sfp detect first\n");
return 0;
} else if (!strcasecmp(args[0], "match")) {
ret = sfp_match();
if (ret == -ENODEV) {
pp_printf("No SFP.\n");
return ret;
}
strncpy(sfp.pn, pn, SFP_PN_LEN);
if (storage_match_sfp(&sfp) > 0) {
pp_printf("SFP matched, dTx=%d, dRx=%d, alpha=%d\n",
sfp.dTx, sfp.dRx, sfp.alpha);
sfp_deltaTx = sfp.dTx;
sfp_deltaRx = sfp.dRx;
sfp_alpha = sfp.alpha;
} else
if (ret == -EIO) {
pp_printf("SFP read error\n");
return ret;
}
/* SFP read correctly */
for (temp = 0; temp < SFP_PN_LEN; ++temp)
pp_printf("%c", sfp_pn[temp]);
pp_printf("\n");
if (ret == -ENXIO) {
pp_printf("Could not match to DB\n");
return ret;
}
/* match successful */
pp_printf("SFP matched, dTx=%d dRx=%d alpha=%d\n",
sfp_deltaTx, sfp_deltaRx, sfp_alpha);
return ret;
} else if (args[1] && !strcasecmp(args[0], "ena")) {
ep_sfp_enable(atoi(args[1]));
return 0;
} else if (args[0] && !strcasecmp(args[0], "ena")) {
if(!args[1])
} else {
pp_printf("Wrong parameter\n");
return -EINVAL;
ep_sfp_enable(atoi(args[1]));
}
return 0;
}
......
......@@ -18,12 +18,23 @@
#define SUPPORT ""
#endif
#ifdef CONFIG_DETERMINISTIC_BINARY
#define DETERMINISTIC_BINARY 1
#else
#define DETERMINISTIC_BINARY 0
#endif
static int cmd_ver(const char *args[])
{
int hwram = sysc_get_memsize();
pp_printf("WR Core build: %s%s\n", build_revision, SUPPORT);
pp_printf("Built: %s %s\n", build_date, build_time); /* may be empty */
/* may be empty if build with CONFIG_DETERMINISTIC_BINARY */
if (DETERMINISTIC_BINARY)
pp_printf("Deterministic binary build\n");
else
pp_printf("Built: %s %s by %s\n", build_date, build_time,
build_by);
pp_printf("Built for %d kB RAM, stack is %d bytes\n",
CONFIG_RAMSIZE / 1024, CONFIG_STACKSIZE);
/* hardware reports memory size, with a 16kB granularity */
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2010 - 2013 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
/* softpll_export.h: public SoftPLL stats API header */
#ifndef __SOFTPLL_EXPORT_H
#define __SOFTPLL_EXPORT_H
#include <stdint.h>
/* SoftPLL operating modes, for mode parameter of spll_init(). */
/* Grand Master - lock to 10 MHz external reference */
#define SPLL_MODE_GRAND_MASTER 1
/* Free running master - 125 MHz refrence free running, DDMTD locked to it */
#define SPLL_MODE_FREE_RUNNING_MASTER 2
/* Slave mode - 125 MHz reference locked to one of the input clocks */
#define SPLL_MODE_SLAVE 3
/* Disabled mode: SoftPLL inactive */
#define SPLL_MODE_DISABLED 4
#define SEQ_START_EXT 1
#define SEQ_WAIT_EXT 2
#define SEQ_START_HELPER 3
#define SEQ_WAIT_HELPER 4
#define SEQ_START_MAIN 5
#define SEQ_WAIT_MAIN 6
#define SEQ_DISABLED 7
#define SEQ_READY 8
#define SEQ_CLEAR_DACS 9
#define SEQ_WAIT_CLEAR_DACS 10
#define AUX_DISABLED 1
#define AUX_LOCK_PLL 2
#define AUX_ALIGN_PHASE 3
#define AUX_READY 4
#define ALIGN_STATE_EXT_OFF 0
#define ALIGN_STATE_START 1
#define ALIGN_STATE_INIT_CSYNC 2
#define ALIGN_STATE_WAIT_CSYNC 3
#define ALIGN_STATE_START_ALIGNMENT 7
#define ALIGN_STATE_WAIT_SAMPLE 4
#define ALIGN_STATE_COMPENSATE_DELAY 5
#define ALIGN_STATE_LOCKED 6
#define ALIGN_STATE_START_MAIN 8
#define ALIGN_STATE_WAIT_CLKIN 9
#define ALIGN_STATE_WAIT_PLOCK 10
#define SPLL_STATS_VER 3
/* info reported through .stat section */
/* due to endiannes problem strings has to be 4 bytes alligned */
struct spll_stats {
int magic; /* 0x5b1157a7 = SPLLSTAT ?;)*/
int ver; /* version of the structure */
int sequence; /* sequence number, so the host can retry */
int mode;
int irq_cnt;
int seq_state;
int align_state;
int H_lock;
int M_lock;
int H_y, M_y;
int del_cnt;
int start_cnt;
char commit_id[32];
char build_date[16];
char build_time[16];
char build_by[32];
};
extern struct spll_stats stats;
#endif /* __SOFTPLL_EXPORT_H */
......@@ -37,22 +37,6 @@ int spll_n_chan_ref, spll_n_chan_out;
#define MAIN_CHANNEL (spll_n_chan_ref)
#define SEQ_START_EXT 1
#define SEQ_WAIT_EXT 2
#define SEQ_START_HELPER 3
#define SEQ_WAIT_HELPER 4
#define SEQ_START_MAIN 5
#define SEQ_WAIT_MAIN 6
#define SEQ_DISABLED 7
#define SEQ_READY 8
#define SEQ_CLEAR_DACS 9
#define SEQ_WAIT_CLEAR_DACS 10
#define AUX_DISABLED 1
#define AUX_LOCK_PLL 2
#define AUX_ALIGN_PHASE 3
#define AUX_READY 4
static const struct stringlist_entry seq_states [] =
{
{ SEQ_START_EXT, "start-ext" },
......@@ -641,8 +625,7 @@ int spll_update()
}
ret += spll_update_aux_clocks();
/* currently we have statistics only in the switch */
if (is_wr_switch) {
/* store statistics */
stats.sequence++;
stats.mode = softpll.mode;
stats.irq_cnt = softpll.irq_count;
......@@ -654,7 +637,7 @@ int spll_update()
stats.M_y = softpll.mpll.pi.y;
stats.del_cnt = softpll.delock_count;
stats.sequence++;
}
return ret != 0;
}
......
......@@ -14,6 +14,7 @@
#include <stdint.h>
#include "util.h"
#include "softpll_export.h"
#include "spll_defs.h"
#include "spll_common.h"
#include "spll_debug.h"
......@@ -23,20 +24,6 @@
#include "spll_external.h"
/* SoftPLL operating modes, for mode parameter of spll_init(). */
/* Grand Master - lock to 10 MHz external reference */
#define SPLL_MODE_GRAND_MASTER 1
/* Free running master - 125 MHz refrence free running, DDMTD locked to it */
#define SPLL_MODE_FREE_RUNNING_MASTER 2
/* Slave mode - 125 MHz reference locked to one of the input clocks */
#define SPLL_MODE_SLAVE 3
/* Disabled mode: SoftPLL inactive */
#define SPLL_MODE_DISABLED 4
/* Shortcut for 'channels' parameter in various API functions to perform operation on all channels */
#define SPLL_ALL_CHANNELS 0xffffffff
......@@ -125,31 +112,6 @@ int spll_get_dac(int out_channel);
void check_vco_frequencies(void);
#define SPLL_STATS_VER 2
/* info reported through .stat section */
/* due to endiannes problem strings has to be 4 bytes alligned */
struct spll_stats {
int magic; /* 0x5b1157a7 = SPLLSTAT ?;)*/
int ver; /* version of the structure */
int sequence; /* sequence number, so the host can retry */
int mode;
int irq_cnt;
int seq_state;
int align_state;
int H_lock;
int M_lock;
int H_y, M_y;
int del_cnt;
int start_cnt;
char commit_id[32];
char build_date[16];
char build_time[16];
};
/* This only exists in wr-switch, but we should use it always */
extern struct spll_stats stats;
/*
* Aux and main state:
* used to be in .c file, but we need it here for memory dumping
......
......@@ -14,17 +14,6 @@
#include "softpll_ng.h"
#include "irq.h"
#define ALIGN_STATE_EXT_OFF 0
#define ALIGN_STATE_START 1
#define ALIGN_STATE_INIT_CSYNC 2
#define ALIGN_STATE_WAIT_CSYNC 3
#define ALIGN_STATE_START_ALIGNMENT 7
#define ALIGN_STATE_WAIT_SAMPLE 4
#define ALIGN_STATE_COMPENSATE_DELAY 5
#define ALIGN_STATE_LOCKED 6
#define ALIGN_STATE_START_MAIN 8
#define ALIGN_STATE_WAIT_CLKIN 9
#define ALIGN_STATE_WAIT_PLOCK 10
#define ALIGN_SAMPLE_PERIOD 100000
#define ALIGN_TARGET 0
......
bats
snmp_test_config.bash
ifndef TARGET_IP
$(error TARGET_IP is not set)
endif
all: test
prepare: bats/libexec/bats
bats/libexec/bats:
@echo "bats not installed!"
@echo "Please perform the following commands:"
@echo "git clone https://github.com/sstephenson/bats"
# be sure which version we use
@echo "cd bats; git checkout 03608115"
@exit 1
test: prepare
bats/libexec/bats snmp_tests_*.bats
SNMP_OPTIONS_NO_M="-On -c public -v 2c "
# be sure you have run download-mibs to download MIBs
SNMP_OPTIONS="$SNMP_OPTIONS_NO_M -m WR-WRPC-MIB -M +/var/lib/mibs/ietf:../../lib"
TOTAL_NUM_OIDS_EXPECT_TEXT="4 temperature sensors, 4 entries in the SFPs database"
# number of OIDs expected
TOTAL_NUM_OIDS=69
helper_snmpget() {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP $1 | grep "$2" | wc -l)"
[ "$result" -eq 1 ]
}
helper_snmpget_oidnotfound() {
run snmpget $SNMP_OPTIONS $TARGET_IP $1
[ "$status" -eq 2 ]
}
helper_snmpget_oidfound() {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP $1 | grep "$1" | wc -l)"
[ "$result" -eq 1 ]
}
helper_snmpgetnext() {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP $1 | grep "$2" | wc -l)"
[ "$result" -eq 1 ]
}
helper_snmpset() {
result="$(snmpset $SNMP_OPTIONS $TARGET_IP $1 = "$2" | grep "$2" | wc -l)"
[ "$result" -eq 1 ]
}
helper_erase_sfp_database() {
result="$(snmpset $SNMP_OPTIONS $TARGET_IP wrpcPtpConfigApply.0 = eraseFlash | grep applySuccessful | wc -l)"
[ "$result" -eq 1 ]
}
load snmp_test_config
@test "Host up $TARGET_IP" {
if [ x"$TARGET_IP" = "x" ]; then
echo "no TARGET_IP set"
fi
# to know if out target system is up
run ping -c 1 $TARGET_IP -W 2
[ "$status" -eq 0 ]
}
@test "Check the presence of snmpget" {
# to know if we have snmpget available
run command -v snmpget
[ "$status" -eq 0 ]
}
@test "Check the presence of snmpgetnext" {
# to know if we have snmpgetnext available
run command -v snmpgetnext
[ "$status" -eq 0 ]
}
@test "Check the presence of snmpwalk" {
# to know if we have snmpwalk available
run command -v snmpwalk
[ "$status" -eq 0 ]
}
@test "Check the presence of snmpset" {
# to know if we have snmpset available
run command -v snmpset
[ "$status" -eq 0 ]
}
load snmp_test_config
load snmp_test_helpers
@test "snmpget existing oid 1.3.6.1.4.1.96.101.1.1.1.0" {
helper_snmpget 1.3.6.1.4.1.96.101.1.1.1.0 1.3.6.1.4.1.96.101.1.1.1.0
}
@test "snmpget existing oid 1.3.6.1.4.1.96.101.1.1.2.0" {
helper_snmpget 1.3.6.1.4.1.96.101.1.1.2.0 1.3.6.1.4.1.96.101.1.1.2.0
[ "$result" -eq 1 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1.96.101.1.1.2" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.2 | grep 1.3.6.1.4.1.96.101.1.1.2 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1.96.101.1.1" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1 | grep 1.3.6.1.4.1.96.101.1.1 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1.96.101.1" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1 | grep 1.3.6.1.4.1.96.101.1 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1.96.101" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1 | grep 1.3.6.1.4.1.96.101.1 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1.96" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96 | grep 1.3.6.1.4.1.96 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpget non existing oid 1.3.6.1.4.1" {
result="$(snmpget $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1 | grep 1.3.6.1.4.1 | wc -l)"
[ "$result" -eq 0 ]
}
load snmp_test_config
@test "Get next object after 1.3.6.1.4.1.96.101.1.1.3.0, check if other returned" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.3.0 | grep 1.3.6.1.4.1.96.101.1.1.3.0 | wc -l)"
[ "$result" -eq 0 ]
}
@test "Get next object after 1.3.6.1.4.1.96.101.1.1.3.0, check if correct returned" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.3.0 | grep 1.3.6.1.4.1.96.101.1.1.4.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after 1.3.6.1.4.1.95 (first object)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.95 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after the last object (getnext 1.3.6.1.4.1.97)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.97 | wc -l)"
[ "$result" -eq 0 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96 (oid too short)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.0 (oid too short with 0 at the end)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.0 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101 (oid too short)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1 (oid too short)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1 (oid too short)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.1 (missing 0 at the end)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.1 | grep 1.3.6.1.4.1.96.101.1.1.1.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.2 (missing 0 at the end)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.2 | grep 1.3.6.1.4.1.96.101.1.1.2.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.1.0 (jump to the next oid in the branch)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.1.0 | grep 1.3.6.1.4.1.96.101.1.1.2.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.1.1 (too deep in the branch)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.1.1 | grep 1.3.6.1.4.1.96.101.1.1.2.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.1.1.1 (too deep in the branch)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.1.1.1 | grep 1.3.6.1.4.1.96.101.1.1.2.0 | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get next object after oid 1.3.6.1.4.1.96.101.1.1.1.1.1.0 (too deep in the branch)" {
result="$(snmpgetnext $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1.1.1.1.0 | grep 1.3.6.1.4.1.96.101.1.1.2.0 | wc -l)"
[ "$result" -eq 1 ]
}
load snmp_test_config
@test "Get Counter64 OID (WR-WRPC-MIB::wrpcPtpAsymmetry.0) with SNMPv2" {
result="$(snmpget $SNMP_OPTIONS -Os $TARGET_IP wrpcPtpAsymmetry.0 | grep "wrpcPtpAsymmetry.0" | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get Counter64 OID (WR-WRPC-MIB::wrpcPtpAsymmetry.0) with SNMPv1 (not supported)" {
# SNMP v1 does not support counter64, so it should return oid not found
result="$(snmpget $SNMP_OPTIONS -Os -v 1 $TARGET_IP wrpcPtpAsymmetry.0 | grep "wrpcPtpAsymmetry.0" | wc -l)"
[ "$result" -eq 0 ]
}
@test "Getnext OID before Counter64 WR-WRPC-MIB::wrpcPtpAsymmetry.0 with SNMPv1" {
# should point after the Counter64 (wrpcPtpRTTErrCnt.0) to the wrpcPtpTx.0
result="$(snmpgetnext $SNMP_OPTIONS -Os -v 1 $TARGET_IP wrpcPtpRTTErrCnt.0 | grep "wrpcPtpTx.0" | wc -l)"
[ "$result" -eq 1 ]
}
@test "Getnext Counter64 OID WR-WRPC-MIB::wrpcPtpAsymmetry.0 with SNMPv1" {
# should point after Counter64 (wrpcPtpAsymmetry.0) to the wrpcPtpTx.0
result="$(snmpgetnext $SNMP_OPTIONS -Os -v 1 $TARGET_IP wrpcPtpAsymmetry.0 | grep "wrpcPtpTx.0" | wc -l)"
[ "$result" -eq 1 ]
}
This diff is collapsed.
load snmp_test_config
load snmp_test_helpers
@test "Get wrpcTemperatureTable" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3
}
@test "Get wrpcTemperatureTable.0" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.0
}
@test "Get wrpcTemperatureTable.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1
}
@test "Get wrpcTemperatureTable.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.1
}
@test "Get wrpcTemperatureTable.1.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.1.1
}
@test "Get wrpcTemperatureTable.1.1.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.1.1.1
}
@test "Get wrpcTemperatureTable.1.2" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.2
}
@test "Get wrpcTemperatureTable.1.2.1" {
helper_snmpget_oidfound .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get wrpcTemperatureTable.1.2.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.2.1.1
}
@test "Get wrpcTemperatureTable.1.2.1.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.2.1.1.1
}
@test "Get wrpcTemperatureTable.1.3" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.3
}
@test "Get wrpcTemperatureTable.1.3.1" {
helper_snmpget_oidfound .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get wrpcTemperatureTable.1.3.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.3.1.1
}
@test "Get wrpcTemperatureTable.1.3.1.1.1" {
helper_snmpget_oidnotfound .1.3.6.1.4.1.96.101.1.3.1.3.1.1.1
}
@test "Get next wrpcTemperatureTable" {
helper_snmpgetnext wrpcTemperatureTable .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.0" {
helper_snmpgetnext wrpcTemperatureTable.0 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1" {
helper_snmpgetnext wrpcTemperatureTable.1 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.1 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.1.1 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.1.1.1 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1.1.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.1.1.1.1 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1.1.1.2" {
helper_snmpgetnext wrpcTemperatureTable.1.1.1.1.2 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.1.2" {
helper_snmpgetnext wrpcTemperatureTable.1.1.2 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.2" {
helper_snmpgetnext wrpcTemperatureTable.1.2 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.2.0" {
helper_snmpgetnext wrpcTemperatureTable.1.2.0 .1.3.6.1.4.1.96.101.1.3.1.2.1
}
@test "Get next wrpcTemperatureTable.1.2.1" {
helper_snmpgetnext wrpcTemperatureTable.1.2.1 .1.3.6.1.4.1.96.101.1.3.1.2.2
}
@test "Get next wrpcTemperatureTable.1.2.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.2.1.1 .1.3.6.1.4.1.96.101.1.3.1.2.2
}
@test "Get next wrpcTemperatureTable.1.2.2" {
helper_snmpgetnext wrpcTemperatureTable.1.2.2 .1.3.6.1.4.1.96.101.1.3.1.2.3
}
@test "Get next wrpcTemperatureTable.1.2.3" {
helper_snmpgetnext wrpcTemperatureTable.1.2.3 .1.3.6.1.4.1.96.101.1.3.1.2.4
}
@test "Get next wrpcTemperatureTable.1.2.4" {
helper_snmpgetnext wrpcTemperatureTable.1.2.4 .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get next wrpcTemperatureTable.1.2.5" {
helper_snmpgetnext wrpcTemperatureTable.1.2.5 .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get next wrpcTemperatureTable.1.3" {
helper_snmpgetnext wrpcTemperatureTable.1.3 .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get next wrpcTemperatureTable.1.3.0" {
helper_snmpgetnext wrpcTemperatureTable.1.3.0 .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get next wrpcTemperatureTable.1.3.0.0" {
helper_snmpgetnext wrpcTemperatureTable.1.3.0.0 .1.3.6.1.4.1.96.101.1.3.1.3.1
}
@test "Get next wrpcTemperatureTable.1.3.1" {
helper_snmpgetnext wrpcTemperatureTable.1.3.1 .1.3.6.1.4.1.96.101.1.3.1.3.2
}
@test "Get next wrpcTemperatureTable.1.3.2" {
helper_snmpgetnext wrpcTemperatureTable.1.3.2 .1.3.6.1.4.1.96.101.1.3.1.3.3
}
@test "Get next wrpcTemperatureTable.1.3.3" {
helper_snmpgetnext wrpcTemperatureTable.1.3.3 .1.3.6.1.4.1.96.101.1.3.1.3.4
}
@test "Get next wrpcTemperatureTable.1.3.4" {
helper_snmpgetnext wrpcTemperatureTable.1.3.4 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.3.4.0" {
helper_snmpgetnext wrpcTemperatureTable.1.3.4.0 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.3.4.1" {
helper_snmpgetnext wrpcTemperatureTable.1.3.4.1 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.3.4.1.1" {
helper_snmpgetnext wrpcTemperatureTable.1.3.4.1.1 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.3.5" {
helper_snmpgetnext wrpcTemperatureTable.1.3.5 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.4" {
helper_snmpgetnext wrpcTemperatureTable.1.4 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.4.0" {
helper_snmpgetnext wrpcTemperatureTable.1.4.0 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.1.4.1" {
helper_snmpgetnext wrpcTemperatureTable.1.4.1 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.2" {
helper_snmpgetnext wrpcTemperatureTable.2 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "Get next wrpcTemperatureTable.2.0" {
helper_snmpgetnext wrpcTemperatureTable.2.0 .1.3.6.1.4.1.96.101.1.4.1.0
}
@test "set read only wrpcTemperatureTable.1.2.1" {
run snmpset $SNMP_OPTIONS $TARGET_IP wrpcTemperatureTable.1.2.1 = 141415
[ "$status" -eq 2 ]
}
load snmp_test_config
@test "snmpwalk 1.3.6.1.4.1.96.101.1.1" {
result="$(snmpwalk $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.96.101.1.1 | wc -l)"
[ "$result" -eq 4 ]
}
@test "snmpwalk 1.3.6.1.4.1.95" {
result="$(snmpwalk $SNMP_OPTIONS $TARGET_IP 1.3.6.1.4.1.95 | wc -l)"
[ "$result" -eq 0 ]
}
@test "snmpwalk 1.3.6 count all OIDs" {
result="$(snmpwalk $SNMP_OPTIONS $TARGET_IP 1.3.6 | wc -l)"
if [ "$result" -ne $TOTAL_NUM_OIDS ]; then
echo "Wrong number of OIDs! We expect $TOTAL_NUM_OIDS, while got $result"
echo "Please check WRPC's configuration. We expect to be in the WRPC:"
echo $TOTAL_NUM_OIDS_EXPECT_TEXT
false
fi
}
#
# Automatically generated make config: don't edit
#
# CONFIG_WR_SWITCH is not set
CONFIG_WR_NODE=y
CONFIG_PRINT_BUFSIZE=128
CONFIG_PRINTF_XINT=y
CONFIG_RAMSIZE=131072
CONFIG_TEMP_POLL_INTERVAL=15
# CONFIG_PLL_VERBOSE is not set
# CONFIG_PFILTER_VERBOSE is not set
# CONFIG_WRC_VERBOSE is not set
# CONFIG_VLAN is not set
CONFIG_VLAN_NR=0
CONFIG_VLAN_1_FOR_CLASS7=0
CONFIG_VLAN_2_FOR_CLASS7=0
CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_LM32=y
CONFIG_EMBEDDED_NODE=y
# CONFIG_WR_NODE_PCS16 is not set
CONFIG_STACKSIZE=2048
CONFIG_PPSI=y
CONFIG_UART=y
CONFIG_W1=y
CONFIG_IP=y
CONFIG_CMD_CONFIG=y
CONFIG_SYSLOG=y
CONFIG_SNMP=y
CONFIG_SNMP_SET=y
CONFIG_SNMP_HW_TYPE="spec"
CONFIG_BUILD_INIT=y
CONFIG_INIT_COMMAND="ptp stop"
CONFIG_HAS_BUILD_INIT=1
CONFIG_HAS_FLASH_INIT=1
CONFIG_FLASH_INIT=y
#
# wrpc-sw is tainted if you change the following options
#
CONFIG_DEVELOPER=y
CONFIG_TEMP_HIGH_THRESHOLD=70
CONFIG_TEMP_HIGH_RAPPEL=60
# CONFIG_CMD_LL is not set
# CONFIG_CHECK_RESET is not set
# CONFIG_SPLL_FIFO_LOG is not set
# CONFIG_PRINTF_FULL is not set
# CONFIG_PRINTF_MINI is not set
# CONFIG_PRINTF_NONE is not set
# CONFIG_DETERMINISTIC_BINARY is not set
# CONFIG_UART_SW is not set
# CONFIG_NET_VERBOSE is not set
# CONFIG_SNMP_VERBOSE is not set
CONFIG_FAKE_TEMPERATURES=y
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
CONFIG_VLAN_ARRAY_SIZE=1
......@@ -38,11 +38,6 @@ int wrc_ui_mode = UI_SHELL_MODE;
int wrc_ui_refperiod = TICS_PER_SECOND; /* 1 sec */
int wrc_phase_tracking = 1;
///////////////////////////////////
//Calibration data (from EEPROM if available)
int32_t sfp_alpha = 73622176; //default values if could not read EEPROM
int32_t sfp_deltaTx = 0;
int32_t sfp_deltaRx = 0;
uint32_t cal_phase_transition = 2389;
int wrc_vlan_number = CONFIG_VLAN_NR;
......@@ -121,6 +116,7 @@ static int wrc_check_link(void)
if (!prev_state && state) {
wrc_verbose("Link up.\n");
gpio_out(GPIO_LED_LINK, 1);
sfp_match();
wrc_ptp_start();
link_status = LINK_WENT_UP;
rv = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment