Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft mac filtering #349

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ set(PNET_MAX_CR 2
set(PNET_MAX_SLOTS 5
CACHE STRING "Per API. Should be > 1 to allow at least one I/O module")
set(PNET_MAX_SUBSLOTS 3
CACHE STRING "Per slot (DAP requires 2 + PNET_MAX_PORT)")
CACHE STRING "Per slot (DAP requires 2 + PNET_NUMBER_OF_PHYSICAL_PORTS)")
set(PNET_MAX_CHANNELS 1
CACHE STRING "Per sub-slot. Used for diagnosis")
set(PNET_MAX_DFP_IOCR 2
CACHE STRING "Allowed values are 0 (zero) or 2")
set(PNET_MAX_PORT 1
set(PNET_NUMBER_OF_PHYSICAL_PORTS 1
CACHE STRING "Number of physical ports")
set(PNET_MAX_LOG_BOOK_ENTRIES 16
CACHE STRING "")
Expand Down
6 changes: 3 additions & 3 deletions doc/multiple_ports.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ To run p-net and the sample application with multiple ports a couple
of things need to be done. Note that the settings described in the
following sections are changed by running ``ccmake .`` in the build folder.
``options.h`` will be regenerated. Another way to set the options is to
set them on the cmake command line (-DPNET_MAX_PORT=2 -DPNET_MAX_SUBSLOTS=4).
set them on the cmake command line (-DPNET_NUMBER_OF_PHYSICAL_PORTS=2 -DPNET_MAX_SUBSLOTS=4).

Reconfigure setting ``PNET_MAX_PORT`` to the actual number of physical ports available in the system.
For this example ``PNET_MAX_PORT`` shall be set to 2.
Reconfigure setting ``PNET_NUMBER_OF_PHYSICAL_PORTS`` to the actual number of physical ports available in the system.
For this example ``PNET_NUMBER_OF_PHYSICAL_PORTS`` shall be set to 2.

Reconfigure setting ``PNET_MAX_SUBSLOTS``. Each additional port will require an additional subslot.
For this example the ``PNET_MAX_SUBSLOTS`` should be be set to 4.
Expand Down
18 changes: 3 additions & 15 deletions include/pnet_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1170,24 +1170,12 @@ typedef struct pnet_ethaddr
#define PNET_LLDP_PORT_ID_MAX_SIZE \
(PNET_STATION_NAME_MAX_SIZE + PNET_PORT_NAME_MAX_SIZE)

/**
* Network interface
*/
typedef struct pnet_netif
{
char if_name[PNET_INTERFACE_NAME_MAX_SIZE]; /**< Terminated string */
pnet_ethaddr_t eth_addr; /**< Interface MAC address */
} pnet_netif_t;

/**
* Physical Port Configuration
*/
typedef struct pnet_port_cfg
{
pnet_netif_t phy_port;
char port_name[PNET_PORT_NAME_MAX_SIZE]; /**< Terminated string */
uint16_t rtclass_2_status;
uint16_t rtclass_3_status;
const char * netif_name;
} pnet_port_cfg_t;

/**
Expand All @@ -1213,10 +1201,10 @@ typedef struct pnet_ip_cfg
*/
typedef struct pnet_if_cfg
{
pnet_netif_t main_port; /**< Main (DAP) network interface. */
const char * main_netif_name; /**< Main (DAP) network interface. */
pnet_ip_cfg_t ip_cfg; /**< IP Settings for main network interface */

pnet_port_cfg_t ports[PNET_MAX_PORT]; /**< Physical ports (DAP ports) */
pnet_port_cfg_t physical_ports[PNET_NUMBER_OF_PHYSICAL_PORTS];
} pnet_if_cfg_t;

/**
Expand Down
4 changes: 2 additions & 2 deletions options.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
#define PNET_MAX_DFP_IOCR @PNET_MAX_DFP_IOCR@
#endif

#if !defined (PNET_MAX_PORT)
#if !defined (PNET_NUMBER_OF_PHYSICAL_PORTS)
/** 2 for media redundancy. Currently only 1 is supported. */
#define PNET_MAX_PORT @PNET_MAX_PORT@
#define PNET_NUMBER_OF_PHYSICAL_PORTS @PNET_NUMBER_OF_PHYSICAL_PORTS@
#endif

#if !defined (PNET_MAX_LOG_BOOK_ENTRIES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Current list works for Raspberry Pi, Linksys usb/ethernet dongle and xmc sample
</MAUTypeList>
</PortSubmoduleItem>
<!--
Enable to support additional port. (PNET_MAX_PORT == 2)
Enable to support additional port. (PNET_NUMBER_OF_PHYSICAL_PORTS == 2)
Add additional PortSubmoduleItems to support additional ports
-->
<!--
Expand Down
106 changes: 20 additions & 86 deletions sample_app/sampleapp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void ip_to_string (pnal_ipaddr_t ip, char * outputstring)
(uint8_t) (ip & 0xFF));
}

void app_mac_to_string (pnal_ethaddr_t mac, char * outputstring)
void app_mac_to_string (pnet_ethaddr_t mac, char * outputstring)
{
snprintf (
outputstring,
Expand Down Expand Up @@ -1276,7 +1276,7 @@ void app_plug_dap (pnet_t * net, void * arg)
PNET_SUBMOD_DAP_INTERFACE_1_PORT_1_IDENT,
&cfg_dap_data);

#if PNET_MAX_PORT >= 2
#if PNET_MAX_PHY_PORTS >= 2
app_exp_submodule_ind (
net,
arg,
Expand All @@ -1288,7 +1288,7 @@ void app_plug_dap (pnet_t * net, void * arg)
&cfg_dap_data);
#endif

#if PNET_MAX_PORT >= 3
#if PNET_MAX_PHY_PORTS >= 3
app_exp_submodule_ind (
net,
arg,
Expand All @@ -1300,7 +1300,7 @@ void app_plug_dap (pnet_t * net, void * arg)
&cfg_dap_data);
#endif

#if PNET_MAX_PORT >= 4
#if PNET_MAX_PHY_PORTS >= 4
app_exp_submodule_ind (
net,
arg,
Expand All @@ -1317,7 +1317,6 @@ void app_plug_dap (pnet_t * net, void * arg)

int app_pnet_cfg_init_default (pnet_cfg_t * stack_config)
{
uint16_t i;
memset (stack_config, 0, sizeof (pnet_cfg_t));
stack_config->tick_us = APP_TICK_INTERVAL_US;

Expand Down Expand Up @@ -1391,18 +1390,6 @@ int app_pnet_cfg_init_default (pnet_cfg_t * stack_config)
/* Timing */
stack_config->min_device_interval = 32; /* Corresponds to 1 ms */

/* LLDP settings */
for (i = 0; i < PNET_MAX_PORT; i++)
{
snprintf (
stack_config->if_cfg.ports[i].port_name,
sizeof (stack_config->if_cfg.ports[i].port_name),
"port-%03d",
i + 1);
stack_config->if_cfg.ports[i].rtclass_2_status = 0;
stack_config->if_cfg.ports[i].rtclass_3_status = 0;
}

/* Network configuration */
stack_config->send_hello = true;
stack_config->if_cfg.ip_cfg.dhcp_enable = false;
Expand All @@ -1415,50 +1402,6 @@ int app_pnet_cfg_init_default (pnet_cfg_t * stack_config)
return 0;
}

/**
* Initialize a network interface configuration from a network
* interface name.
* This includes reading the Ethernet MAC address.
* If the network interface can not be found or the operation
* fails to read the mac address from the network interface,
* error is returned.
* @param netif_name In: Network interface name
* @param p_netif Out: Network interface configuration
* @param verbosity In: Verbosity
* @return 0 on success
* -1 on error
*/
int app_port_cfg_init (
const char * netif_name,
pnet_netif_t * p_netif,
int verbosity)
{
pnal_ethaddr_t mac;
char mac_string[PNAL_ETH_ADDRSTR_SIZE]; /* Terminated string */

int ret = pnal_get_macaddress (netif_name, &mac);
if (ret != 0)
{
printf (
"Error: The given network interface does not exist: \"%s\"\n",
netif_name);
return -1;
}
else
{
if (verbosity > 0)
{
app_mac_to_string (mac, mac_string);
printf ("%-10s %s\n", netif_name, mac_string);
}
}

strncpy (p_netif->if_name, netif_name, PNET_INTERFACE_NAME_MAX_SIZE);
memcpy (p_netif->eth_addr.addr, mac.addr, sizeof (pnal_ethaddr_t));

return 0;
}

int app_get_netif_namelist (
const char * arg_str,
app_netif_namelist_t * p_if_list,
Expand Down Expand Up @@ -1528,6 +1471,7 @@ int app_get_netif_namelist (

int app_pnet_cfg_init_netifs (
const char * netif_list_str,
app_netif_namelist_t * if_list,
pnet_cfg_t * p_cfg,
int verbosity)
{
Expand All @@ -1536,48 +1480,38 @@ int app_pnet_cfg_init_netifs (
pnal_ipaddr_t ip;
pnal_ipaddr_t netmask;
pnal_ipaddr_t gateway;
app_netif_namelist_t if_list;

ret = app_get_netif_namelist (netif_list_str, &if_list, PNET_MAX_PORT);
ret = app_get_netif_namelist (
netif_list_str,
if_list,
PNET_NUMBER_OF_PHYSICAL_PORTS);
if (ret != 0)
{
return ret;
}
p_cfg->if_cfg.main_netif_name = if_list->netif[0].name;

if (verbosity > 0)
{
printf ("Management port: ");
}
if (
app_port_cfg_init (
if_list.netif[0].name,
&p_cfg->if_cfg.main_port,
verbosity) != 0)
{
return -1;
printf ("Management port: %s\n", p_cfg->if_cfg.main_netif_name);
}

for (i = 1; i <= PNET_MAX_PORT; i++)
for (i = 1; i <= PNET_NUMBER_OF_PHYSICAL_PORTS; i++)
{
p_cfg->if_cfg.physical_ports[i - 1].netif_name = if_list->netif[i].name;
if (verbosity > 0)
{
printf ("Physical port [%u]: ", i);
}

if (
app_port_cfg_init (
if_list.netif[i].name,
&p_cfg->if_cfg.ports[i - 1].phy_port,
verbosity) != 0)
{
return -1;
printf (
"Physical port [%u]: %s\n",
i,
p_cfg->if_cfg.physical_ports[i - 1].netif_name);
}
}

/* Read IP, netmask, gateway from operating system */
ip = pnal_get_ip_address (if_list.netif[0].name);
netmask = pnal_get_netmask (if_list.netif[0].name);
gateway = pnal_get_gateway (if_list.netif[0].name);
ip = pnal_get_ip_address (p_cfg->if_cfg.main_netif_name);
netmask = pnal_get_netmask (p_cfg->if_cfg.main_netif_name);
gateway = pnal_get_gateway (p_cfg->if_cfg.main_netif_name);

if (verbosity > 0)
{
Expand Down
31 changes: 16 additions & 15 deletions sample_app/sampleapp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static const cfg_submodule_type_t cfg_available_submodule_types[] = {
PNET_DIR_NO_IO,
0,
0},
#if PNET_MAX_PORT >= 2
#if PNET_NUMBER_OF_PHYSICAL_PORTS >= 2
{"DAP Port 2",
APP_API,
PNET_MOD_DAP_IDENT,
Expand All @@ -140,7 +140,7 @@ static const cfg_submodule_type_t cfg_available_submodule_types[] = {
0,
0},
#endif
#if PNET_MAX_PORT >= 3
#if PNET_NUMBER_OF_PHYSICAL_PORTS >= 3
{"DAP Port 3",
APP_API,
PNET_MOD_DAP_IDENT,
Expand All @@ -149,7 +149,7 @@ static const cfg_submodule_type_t cfg_available_submodule_types[] = {
0,
0},
#endif
#if PNET_MAX_PORT >= 4
#if PNET_NUMBER_OF_PHYSICAL_PORTS >= 4
{"DAP Port 4",
APP_API,
PNET_MOD_DAP_IDENT,
Expand Down Expand Up @@ -190,8 +190,8 @@ struct cmd_args
char path_storage_directory[PNET_MAX_DIRECTORYPATH_SIZE]; /** Terminated */
char station_name[PNET_STATION_NAME_MAX_SIZE]; /** Terminated string */
char eth_interfaces
[PNET_INTERFACE_NAME_MAX_SIZE * (PNET_MAX_PORT + 1) +
PNET_MAX_PORT]; /** Terminated string */
[PNET_INTERFACE_NAME_MAX_SIZE * (PNET_NUMBER_OF_PHYSICAL_PORTS + 1) +
PNET_NUMBER_OF_PHYSICAL_PORTS]; /** Terminated string */
int verbosity;
int show;
bool factory_reset;
Expand All @@ -205,7 +205,7 @@ typedef struct app_netif_name

typedef struct app_netif_namelist
{
app_netif_name_t netif[PNET_MAX_PORT + 1];
app_netif_name_t netif[PNET_NUMBER_OF_PHYSICAL_PORTS + 1];
} app_netif_namelist_t;

typedef struct app_subslot
Expand Down Expand Up @@ -242,6 +242,7 @@ typedef struct app_data_obj
bool alarm_allowed;
pnet_alarm_argument_t alarm_arg;
struct cmd_args arguments;
app_netif_namelist_t if_list;
uint32_t app_param_1;
uint32_t app_param_2;
uint8_t inputdata[APP_DATASIZE_INPUT];
Expand Down Expand Up @@ -276,7 +277,7 @@ typedef enum app_demo_state
* @param outputstring Out: Resulting string buffer. Should have size
* PNAL_ETH_ADDRSTR_SIZE.
*/
void app_mac_to_string (pnal_ethaddr_t mac, char * outputstring);
void app_mac_to_string (pnet_ethaddr_t mac, char * outputstring);

/**
* Print out current IP address, netmask and default gateway.
Expand Down Expand Up @@ -306,31 +307,31 @@ int app_pnet_cfg_init_default (pnet_cfg_t * stack_config);
*
* @param netif_list_str In: Comma separated list of network interfaces.
* Terminated string.
* @param if_list Out: Network interface string storage.
* @param p_cfg InOut: p-net configuration
* @param verbosity In: Verbosity
* @return 0 on success
* -1 on error
*/
int app_pnet_cfg_init_netifs (
const char * netif_list_str,
app_netif_namelist_t * if_list,
pnet_cfg_t * p_cfg,
int verbosity);

/**
* Parse a comma separated list of network interfaces and check
* that the number of interfaces match the PNET_MAX_PORT configuration.
* Examples:
* PNET_MAX_PORT arg_str status
* 1 "eth0" ok
* 1 "eth0,eth1" err
* 2 "br0,eth0,eth1" ok
* 2 "br0,eth0," err
* that the number of interfaces match the PNET_NUMBER_OF_PHYSICAL_PORTS
* configuration. Examples: PNET_NUMBER_OF_PHYSICAL_PORTS arg_str status 1
* "eth0" ok 1 "eth0,eth1" err 2
* "br0,eth0,eth1" ok 2 "br0,eth0," err
*
* @param arg_str In: Network interface list as comma separated,
* terminated string. For example "eth0" or
* "br0,eth0,eth1".
* @param p_if_list Out: List of network interfaces
* @param max_port In: PNET_MAX_PORT, passed as argument to allow test
* @param max_port In: PNET_NUMBER_OF_PHYSICAL_PORTS, passed as argument to
* allow test
* @return 0 if network interface list matches configuration
* -1 on error
*/
Expand Down
2 changes: 1 addition & 1 deletion src/common/pf_cpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ int pf_cpm_activate_req (pnet_t * net, pf_ar_t * p_ar, uint32_t crep)
(uint32_t)p_iocr->param.reduction_ratio * 1000U) /
32U; /* us */

for (ix = 0; ix < PNET_MAX_PORT; ix++)
for (ix = 0; ix < PNET_NUMBER_OF_PHYSICAL_PORTS; ix++)
{
p_cpm->rxa[ix][0] = -1; /* "invalid" cycle counter */
p_cpm->rxa[ix][1] = -1;
Expand Down
Loading