Commit bbc6b291 authored by Jean-Claude BAU's avatar Jean-Claude BAU

VLANS: Change behavior and add raw configuration

parents fd042d17 87a2d1b6
This diff is collapsed.
This diff is collapsed.
#!/bin/bash
# Adam Wujek, CERN
# Generate Kconfig entries for Vlans
# redirect the output to the proper file
echo "menu \"VLANs\""
echo "config VLANS_ENABLE"
echo " bool \"Enable VLANs\""
echo " default n"
echo " help"
echo " Enable VLAN configuration via dot-config"
echo ""
echo "menu \"Ports configuration\""
echo " depends on VLANS_ENABLE"
############# generate options for ports
for port_i in {1..18}; do
port_0i=$(printf "%02d" $port_i)
echo ""
echo "comment \"Port $port_i\""
echo "choice VLANS_PORT"$port_0i"_MODE"
echo " prompt \"Port "$port_i" VLAN mode\""
echo " default VLANS_PORT"$port_0i"_MODE_UNQUALIFIED"
echo " help"
if [ $port_i -eq 1 ]; then
echo " In terms of VLAN-tag, there are four types of VLAN-tags that can"
echo " extend the Ethernet Frame header:"
echo " * none - tag is not included in the Ethernet Frame"
echo " * priority - tag that has VID=0x0"
echo " * VLAN - tag that has VID in the range 0x001 to 0xFFE"
echo " * null - tag that has VID=0xFFF"
echo ""
echo " The behaviour of each PMODE that can be set per-port depends on the"
echo " type of VLAN-tag in the received frame."
echo ""
echo " - PMODE=access (0x0), frames with:"
echo " * no VLAN-tag : are admitted, tagged with the values of VID and"
echo " priority that are configured in PORT_VID and"
echo " PRIO_VAL respectively"
echo " * priority tag : are admitted, their tag is unchanged, the value of"
echo " VID provided to the RTU is overridden with the"
echo " configured in PORT_VID. If PRIO_VAL is not -1,"
echo " the value of priority provided to RTU is"
echo " overridden with the configured PRIO_VAL"
echo " * VLAN tag : are discarded"
echo " * null tag : are discarded"
echo ""
echo " - PMODE=trunk (0x1), frames with:"
echo " * no VLAN-tag : are discarded"
echo " * priority tag : are discarded"
echo " * VLAN tag : are admitted; if PRIO_VAL is not -1, the value of"
echo " priority provided to RTU is overridden with"
echo " the configured PRIO_VAL"
echo " * null tag : are discarded"
echo ""
echo " - PMODE=disabled (0x2), frames with:"
echo " * no VLAN-tag : are admitted. No other configuration is used even"
echo " if set."
echo " * priority tag : are admitted; if PRIO_VAL is not -1, the value of"
echo " priority provided to RTU is overridden with"
echo " the configured PRIO_VAL"
echo " * VLAN tag : are admitted; if PRIO_VAL is not -1, the value of"
echo " priority provided to RTU is overridden with"
echo " the configured PRIO_VAL"
echo " * null tag : are admitted; if PRIO_VAL is not -1, the value of"
echo " priority provided to RTU is overridden with"
echo " the configured PRIO_VAL"
echo ""
echo " - PMODE=unqualified (0x3), frames with:"
echo " * no VLAN-tag : are admitted. No other configuration is used even"
echo " if set."
echo " * priority tag : are admitted. Their tag is unchanged, the value of"
echo " VID provided to the RTU is overridden with the"
echo " configured in PORT_VID. If PRIO_VAL is not -1,"
echo " the value of priority provided to RTU is"
echo " overridden with the configured PRIO_VAL"
echo " NOTE: providing a VID for this mode is not"
echo " supported in the dot-config"
echo " * VLAN tag : are admitted; if PRIO_VAL is not -1, the value of"
echo " priority provided to RTU is overridden with"
echo " the configured PRIO_VAL"
echo " * null tag : discarded."
else
echo " Please check the help of VLANS_PORT01_MODE"
fi
echo ""
echo "config VLANS_PORT"$port_0i"_MODE_ACCESS"
echo " bool \"Access mode\""
echo " help"
echo " Please check the help of VLANS_PORT01_MODE"
echo ""
echo "config VLANS_PORT"$port_0i"_MODE_TRUNK"
echo " bool \"Trunk mode\""
echo " help"
echo " Please check the help of VLANS_PORT01_MODE"
echo ""
echo "config VLANS_PORT"$port_0i"_MODE_DISABLED"
echo " bool \"VLAN-disabled mode\""
echo " help"
echo " Please check the help of VLANS_PORT01_MODE"
echo ""
echo "config VLANS_PORT"$port_0i"_MODE_UNQUALIFIED"
echo " bool \"Unqualified mode\""
echo " help"
echo " Please check the help of VLANS_PORT01_MODE"
echo ""
echo "endchoice"
echo ""
echo "choice VLANS_PORT"$port_0i"_UNTAG"
echo " prompt \"Port "$port_i" untag frames\""
echo " default VLANS_PORT"$port_0i"_UNTAG_ALL"
echo " depends on VLANS_PORT"$port_0i"_MODE_ACCESS"
echo " help"
echo " Decide whether VLAN-tags should be removed"
echo ""
echo "config VLANS_PORT"$port_0i"_UNTAG_ALL"
echo " bool \"untag all\""
echo " help"
echo " Untag all tagged frames."
echo ""
echo "config VLANS_PORT"$port_0i"_UNTAG_NONE"
echo " bool \"untag none\""
echo " help"
echo " Keep VLAN tags for all tagged frames."
echo ""
echo "endchoice"
echo ""
echo "config VLANS_PORT"$port_0i"_PRIO"
echo " int \"Port "$port_i" priority\""
echo " default -1"
echo " range -1 7"
echo " help"
echo " Priority value used when tagging frames or to override priority passed"
echo " to RTU."
echo " -1 disables the priority overwrite. Valid values are from -1 to 7."
echo ""
echo "config VLANS_PORT"$port_0i"_VID"
echo " string \"Port "$port_i" VID\""
echo " default \"\""
echo " help"
echo " This value based on the port's mode is used as:"
echo " --MODE_ACCESS - (mandatory) use as VID for tagging incoming frames and notify"
echo " the PPSI which VLAN shall it use for synchronization; only one VLAN"
echo " number shall be used in this mode"
echo " --MODE_TRUNK - (optional) notify the PPSI which VLAN shall it use for"
echo " synchronization; semicolon separated list is allowed"
echo " --MODE_DISABLED - (optional) notify the PPSI which VLANs shall it use for"
echo " synchronization; semicolon separated list is allowed"
echo " --MODE_UNQUALIFIED - (optional) notify the PPSI which VLANs shall it use for"
echo " synchronization; semicolon separated list is allowed;"
echo " The range of a valid VID is 0 to 4094"
echo ""
done
echo "# Ports configuration"
echo "endmenu"
################## VLANS configuration
echo "menu \"VLANs configuration\""
echo " depends on VLANS_ENABLE"
echo ""
for set_i in {1..3}; do
if [ $set_i == "1" ]; then
vlan_min=0
vlan_max=22
fi
if [ $set_i == "2" ]; then
vlan_min=23
vlan_max=100
fi
if [ $set_i == "3" ]; then
vlan_min=101
vlan_max=4094
fi
vlan_min_0=$(printf "%04d" $vlan_min)
echo "config VLANS_ENABLE_SET"$set_i
echo " bool \"Enable configuration for VLANs "$vlan_min"-"$vlan_max"\""
echo " default n"
echo " help"
echo ""
echo "menu \"Configuration for VLANs "$vlan_min"-"$vlan_max"\""
echo " depends on VLANS_ENABLE_SET"$set_i
for ((vlan_i=$vlan_min;vlan_i<=$vlan_max;vlan_i++));do
vlan_0i=$(printf "%04d" $vlan_i)
echo "config VLANS_VLAN"$vlan_0i
echo " string \"VLAN"$vlan_i" configuration\""
echo " default \"\""
echo " help"
if [ $vlan_i -eq $vlan_min ]; then
# for the first VLAN in the menu print full help
echo " Provide the configuration for VLAN"$vlan_i
echo " Example:"
echo " fid="$vlan_min",prio=4,drop=no,ports=1;2;3-5;7"
echo " Where:"
echo " --\"fid\" is a associated Filtering ID (FID) number. One FID can be"
echo " associated with many VIDs. RTU learning is performed per-FID."
echo " Associating many VIDs with a single FID allowed shared-VLANs"
echo " learning."
echo " --\"prio\" is a priority of a VLAN; can take values between -1 and 7"
echo " -1 disables priority override, any other valid value takes"
echo " precedence over port priority"
echo " --If \"drop\" is set to y, yes or 1 all frames belonging to this VID are"
echo " dropped (note that frame can belong to a VID as a consequence of"
echo " per-port Endpoint configuration); can take values y, yes, 1, n, no, 0"
echo " --\"ports\" is a list of ports separated with a semicolon sign (\";\");"
echo " ports ranges are supported (with a minus sign)"
else
# for the rest just refer to the first VLAN in the menu
echo " Please check the help of VLANS_VLAN"$vlan_min_0
fi
echo ""
done
echo "# Configuration for VLANs "$vlan_min"-"$vlan_max""
echo "endmenu"
echo ""
echo ""
done
echo "# VLANs configuration"
echo "endmenu"
echo ""
echo "# VLANs"
echo "endmenu"
......@@ -542,11 +542,12 @@ for i_port in {01..18}; do # scan all the physical ports
# add vlans
if [ "$CONFIG_VLANS_ENABLE" = "y" ]; then
unset ppsi_vlans;
unset port_vid;
unset port_mode_access;
unset port_mode_trunk;
unset port_mode_unqualified;
unset port_mode_disabled;
unset port_ptp_vid
# check port mode
port_mode_access=$(eval "echo \$CONFIG_VLANS_PORT"$i_port"_MODE_ACCESS")
......@@ -554,16 +555,22 @@ for i_port in {01..18}; do # scan all the physical ports
port_mode_unqualified=$(eval "echo \$CONFIG_VLANS_PORT"$i_port"_MODE_UNQUALIFIED")
port_mode_disabled=$(eval "echo \$CONFIG_VLANS_PORT"$i_port"_MODE_DISABLED")
port_vid=$(eval "echo \$CONFIG_VLANS_PORT"$i_port"_VID")
port_ptp_vid=$(eval "echo \$CONFIG_VLANS_PORT"$i_port"_PTP_VID")
if [ -z "$port_ptp_vid" ] ; then
port_ptp_vid=$port_vid
fi
# check port mode
if [ "$port_mode_access" = "y" ]; then
ppsi_vlans=$(eval "echo \$CONFIG_VLANS_PORT"$i_port"_VID")
# use "&> /dev/null" to avoid error when $ppsi_vlans
# is not a number
if [ "$ppsi_vlans" -ge 0 ] &> /dev/null \
&& [ "$ppsi_vlans" -le 4094 ] &> /dev/null; then
v="$inst_vn[vlan]"; eval ${v}="$ppsi_vlans"
if [ "$port_ptp_vid" -ge 0 ] &> /dev/null \
&& [ "$port_ptp_vid" -le 4094 ] &> /dev/null; then
v="$inst_vn[vlan]"; eval ${v}="$port_ptp_vid"
else
echo "$script_name: Wrong value \"$ppsi_vlans\" in CONFIG_VLANS_PORT"$i_port"_VID" | tee $log_output
echo "$script_name: Wrong value \"$port_ptp_vid\" in CONFIG_VLANS_PORT"$i_port"_VID" | tee $log_output
continue;
fi
fi
......@@ -571,9 +578,8 @@ for i_port in {01..18}; do # scan all the physical ports
if [ "$port_mode_trunk" = "y" ] \
|| [ "$port_mode_disabled" = "y" ] \
|| [ "$port_mode_unqualified" = "y" ]; then
ppsi_vlans=$(eval "echo \$CONFIG_VLANS_PORT"$i_port"_VID")
if [ -n "$ppsi_vlans" ]; then
mod_vlans=${ppsi_vlans//;/,}
if [ -n "$port_ptp_vid" ]; then
mod_vlans=${port_ptp_vid//;/,}
v="$inst_vn[vlan]"; eval ${v}="$mod_vlans"
fi
fi
......
......@@ -26,6 +26,7 @@
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <minipc.h>
#include <rtud_exports.h>
#include "regs/endpoint-regs.h"
......@@ -387,6 +388,25 @@ int main(int argc, char *argv[])
return 0;
}
static char *trimWhitespace(char *str)
{
char *end;
// Trim leading space
while(isspace((unsigned char)*str)) str++;
if(*str == 0) // All spaces?
return str;
// Trim trailing space
end = str + strlen(str) - 1;
while(end > str && isspace((unsigned char)*end)) end--;
// Write new null terminator character
end[1] = '\0';
return str;
}
static void set_p_pmode(int ep, int arg_mode)
{
vlans[ep].pmode = arg_mode;
......@@ -985,6 +1005,7 @@ static int read_dot_config(char *dot_config_file)
char *val_ch;
int i;
int mode;
int rawPortConfig;
int vlan0_port_mask = 0;
if (access(dot_config_file, R_OK)) {
......@@ -1035,6 +1056,10 @@ static int read_dot_config(char *dot_config_file)
return -2;
}
/* Check if raw configuration is enabled */
ret = libwr_cfg_get("VLANS_RAW_PORT_CONFIG");
rawPortConfig= ret && (!strcmp(ret, "y"));
for (port = 1; port <= NPORTS; port++) {
portmask = portmask | (1 << (port - 1));
mode = QMODE_INVALID;
......@@ -1073,8 +1098,10 @@ static int read_dot_config(char *dot_config_file)
}
/* check UNTAG all or none only for ACCESS
* for other modes use untag none by default */
if (mode == QMODE_ACCESS) {
* for other modes use untag none by default.
* If raw port configuration is enable, does not
* take care of the mode */
if (rawPortConfig || mode == QMODE_ACCESS) {
sprintf(buff, "VLANS_PORT%02d_UNTAG_ALL", port);
ret = libwr_cfg_get(buff);
if (ret && !strcmp(ret, "y")) {
......@@ -1099,28 +1126,51 @@ static int read_dot_config(char *dot_config_file)
}
/* update a mask for vlan0 */
if (mode != QMODE_ACCESS && mode != QMODE_TRUNK) {
if (rawPortConfig || (mode != QMODE_ACCESS && mode != QMODE_TRUNK) ) {
vlan0_port_mask |= 1 << (port - 1);
}
sprintf(buff, "VLANS_PORT%02d_PRIO", port);
val_ch = libwr_cfg_get(buff);
if (val_ch) {
if (wrs_msg_level >= LOG_DEBUG)
printf("Found %s=%s\n", buff, val_ch);
set_p_prio(port - 1, val_ch);
// Priority
if (rawPortConfig || mode != QMODE_TRUNK) {
char *strPrio;
sprintf(buff, "VLANS_PORT%02d_PRIO", port);
val_ch = libwr_cfg_get(buff);
strPrio= val_ch ? trimWhitespace(val_ch) : "";
if (strPrio[0]!=0 ) {
if (wrs_msg_level >= LOG_DEBUG)
printf("Found %s=%s\n", buff, strPrio);
set_p_prio(port - 1, strPrio);
} else {
if ( mode != QMODE_TRUNK ) {
pr_error("Priority not defined for the port (%d) in"
" TRUNK mode!\n", port);
}
if ( !rawPortConfig ) {
exit(1); /* Exit only if not raw port configuration */
}
}
}
if (mode == QMODE_ACCESS) {
// PVID
if (rawPortConfig || mode == QMODE_ACCESS) {
char *strVid;
sprintf(buff, "VLANS_PORT%02d_VID", port);
val_ch = libwr_cfg_get(buff);
if (val_ch) {
strVid= val_ch ? trimWhitespace(val_ch) : "";
if (strVid[0]!=0 ) {
if (wrs_msg_level >= LOG_DEBUG)
printf("Found %s=%s\n", buff, val_ch);
set_p_vid(port - 1, val_ch);
printf("Found %s=%s\n", buff, strVid);
set_p_vid(port - 1, strVid);
} else {
pr_error("VID not defined for the port (%d) in"
" ACCESS mode!\n", port);
exit(1);
if ( mode == QMODE_ACCESS )
pr_error("VID not defined for the port (%d) in"
" ACCESS mode!\n", port);
if ( !rawPortConfig ) {
exit(1); /* Exit only if not raw port configuration */
}
}
}
}
......
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