📄 cli.c
字号:
// option description:
// tsrvPriEn[]: the service priority enable map (sd-d-d-d-d-d: 6 digits option)
// tsrvpriQID: the TOS priority queue ID (q0..q7)
// tsrvQOpt: the TOS priority queue option (m0..m3)
for (i = 0; i < SWI_MAX_PORT_NUMBER; i++) {
tsrvPriEn[i] = 0;
}
// Get the service priority enable map.
sscanf(argv[1], "s%d-%d-%d-%d-%d-%d", &tsrvPriEn[0], &tsrvPriEn[1], &tsrvPriEn[2], &tsrvPriEn[3],
&tsrvPriEn[4], &tsrvPriEn[5]);
// Get the traffic service priority queue ID.
sscanf(argv[2], "q%d", &tsrvpriQID);
if ((tsrvpriQID < 0) || (tsrvpriQID > 63)) {
printf("ArgErr: the traffic service priority queue ID must be in 0..63 !\n");
return;
}
// Get the traffic service priority queue option
sscanf(argv[3], "m%d", &tsrvQOpt);
if ((tsrvQOpt < 0) || (tsrvQOpt > 3)) {
printf("ArgErr: the traffic service priority queue option must be in 0..3 !\n");
return;
}
SWSrvPriConfig(tsrvPriEn, tsrvpriQID, tsrvQOpt);
printf("SrvPriConfig: QID=%d, QOpt=%#x\n", tsrvpriQID, tsrvQOpt);
for (i = 0; i < SWI_MAX_PORT_NUMBER; i++) {
printf("PriEn[%d]=%d,", i, tsrvPriEn[i]);
if (i == 2)
printf("\n");
}
printf("\n");
}
/************************************************************************************/
/* CmdBroadcastStormConfig: */
/************************************************************************************/
void CmdBroadcastStormConfig(int argc, char **argv)
{
int stormEnable, dropEnable, thres100Mbp, thres10Mbp, mulpktStorm;
// option description:
// stormEnable: the broadcast storm protection enable/disable (-s/-S)
// dropEnable: the broadcast storm drop enable/disable (-d/-D)
// thres100Mbp: the 100Mbps threshold for the broadcast storm protection (H0..8191)
// thres10Mbp: the 10Mbps threshold for the broadcast storm protection (h0..8191)
// mulpktStorm: the multicast packet counted into the storm counter <-m/-M>
stormEnable = dropEnable = 0;
mulpktStorm = 2;
// Get the broadcast storm enable.
if (strcmp(argv[1], "-s") == 0)
stormEnable = 1;
else if (strcmp(argv[1], "-S") == 0)
stormEnable = 0;
else {
printf("ArgErr: the option for the broadcast storm enable is <-s> or <-S> !\n");
return;
}
// Get the broadcast storm drop.
if (strcmp(argv[2], "-d") == 0)
dropEnable = 1;
else if (strcmp(argv[2], "-D") == 0)
dropEnable = 0;
else {
printf("ArgErr: the option for the broadcast storm drop is <-d> or <-D> !\n");
return;
}
// Get the 100Mbps threshold value.
sscanf(argv[3], "H%d", &thres100Mbp);
if ((thres100Mbp < 0) || (thres100Mbp > 8191)) {
printf("ArgErr: the 100Mbps threshold must be in 0..8191 !\n");
return;
}
// Get the 10Mbps threshold value.
sscanf(argv[4], "h%d", &thres10Mbp);
if ((thres10Mbp < 0) || (thres10Mbp > 8191)) {
printf("ArgErr: the 10Mbps threshold must be in 0..8191 !\n");
return;
}
// Get the multicast packet storm enable.
if (argc > 5) {
if (strcmp(argv[5], "-m") == 0)
mulpktStorm = 1;
else if (strcmp(argv[5], "-M") == 0)
mulpktStorm = 0;
else {
printf("ArgErr: the option for the multicast storm enable is <-m> or <-M> !\n");
return;
}
}
SWBrdStormConfig(stormEnable, dropEnable, thres100Mbp, thres10Mbp, mulpktStorm);
printf("BrdStormConfig: StormEn=%d, dropEn=%d, ths100M=%d, ths10M=%d, mulStm=%d\n", stormEnable, dropEnable, thres100Mbp, thres10Mbp, mulpktStorm);
}
/************************************************************************************/
/* CmdTxBandWidthConfig: */
/************************************************************************************/
void CmdTxBandWidthConfig(int argc, char **argv)
{
int port_no, txBWCEnable = 1, txBWThresh = 1;
// option description:
// port_no: the port number (0..5)
// txBWCEnable: the transmit bandwidth control enable (-o/-O)
// txBWThresh: the transmit bandwidth threshold (hhhh: 1..1526)
// Get the port_no.
sscanf(argv[1], "%d", &port_no);
if ((port_no < 0) || (port_no > 5)) {
printf("ArgErr: the port_no must be in 0..5 !\n");
return;
}
// Get the transmit bandwidth control enable value.
if (strcmp(argv[2], "-O") == 0)
txBWCEnable = 0;
sscanf(argv[3], "%d", &txBWThresh);
if ((txBWThresh < 1) || (txBWThresh > 1526)) {
printf("ArgErr: the transmit bandwidth threshold must be in 1..1526 !\n");
return;
}
SWTxBandConfig(port_no, txBWCEnable, txBWThresh);
printf("CmdTxBandWidthConfig: port[%d].TBWT=%d, TBWCEn=%d\n", port_no, txBWThresh, txBWCEnable);
}
/************************************************************************************/
/* CmdRxBandWidthConfig: */
/************************************************************************************/
void CmdRxBandWidthConfig(int argc, char **argv)
{
int port_no, rxBWCEnable = 1, rxBWThresh = 1;
// option description:
// port_no: the port number (0..5)
// rxBWCEnable: the receive bandwidth control enable (-o/-O)
// rxBWThresh: the receive bandwidth threshold (hhhh: 1..1526)
// Get the port_no.
sscanf(argv[1], "%d", &port_no);
if ((port_no < 0) || (port_no > 5)) {
printf("ArgErr: the port_no must be in 0..5 !\n");
return;
}
// Get the transmit bandwidth control enable value.
if (strcmp(argv[2], "-O") == 0)
rxBWCEnable = 0;
sscanf(argv[3], "%d", &rxBWThresh);
if ((rxBWThresh < 1) || (rxBWThresh > 1526)) {
printf("ArgErr: the receive bandwidth threshold must be in 1..1526 !\n");
return;
}
SWRxBandConfig(port_no, rxBWCEnable, rxBWThresh);
printf("CmdRxBandWidthConfig: port[%d].RBWT=%d, RBWCEn=%d\n", port_no, rxBWThresh, rxBWCEnable);
}
/************************************************************************************/
/* CmdPortSecurityConfig: */
/************************************************************************************/
void CmdPortSecurityConfig(int argc, char **argv)
{
int port_no, portSecOpt, closePort = -1;
// option description:
// port_no: the port number (0..5)
// portSecOpt: the port security option (s1..s6)
// closePort: the close port option (-c/-C)
// Get the port_no.
sscanf(argv[1], "%d", &port_no);
if ((port_no < 0) || (port_no > 5)) {
printf("ArgErr: the port_no must be in 0..5 !\n");
return;
}
// Get the port security option.
sscanf(argv[2], "s%d", &portSecOpt);
if ((portSecOpt < 1) || (portSecOpt > 6)) {
printf("ArgErr: the port security option must be in 1..6 !\n");
return;
}
if (argc > 3) {
// Get the close port option.
if (strcmp(argv[3], "-c") == 0)
closePort = 1;
else if (strcmp(argv[3], "-C") == 0)
closePort = 0;
else {
printf("ArgErr: the port security option must be as -c/-C !\n");
return;
}
}
SWPortSecurityConfig(port_no, portSecOpt, closePort);
printf("CmdPortSecurityConfig: port[%d], secOpt=%d, close=%d\n", port_no, portSecOpt, closePort);
}
/************************************************************************************/
/* CmdSecurityOptionConfig: */
/************************************************************************************/
void CmdSecurityOptionConfig(int argc, char **argv)
{
int i;
int sourceIntrusion[SWI_SOURCE_INTRUDE_MAXOPT], sourceViolation[SWI_SOURCE_VIOLATE_MAXOPT];
// option description:
// sourceIntrusion[]: the option number for the source intrusion (id-d-d)
// i[0]: the source intrusion action, i[1]: the source intrusion must,
// i[2]: the source intrusion condition
// sourceViolation[]: the option number for the source violation (vd-d-d-d)
// v[0]: the source violation over default, v[1]: the source violation over snooping,
// v[2]: the source violation over arp/rarp. v[3]: the source violation over reserve
for (i = 0; i < SWI_SOURCE_INTRUDE_MAXOPT; i++) {
sourceIntrusion[i] = 0;
}
for (i = 0; i < SWI_SOURCE_VIOLATE_MAXOPT; i++) {
sourceViolation[i] = 0;
}
// Get the option number for the source intrusion.
sscanf(argv[1], "i%d-%d-%d", &sourceIntrusion[0], &sourceIntrusion[1], &sourceIntrusion[2]);
// Get the option number for the source violation.
sscanf(argv[2], "v%d-%d-%d-%d", &sourceViolation[0], &sourceViolation[1], &sourceViolation[2], &sourceViolation[3]);
SWSecurityOptionConfig(sourceIntrusion, sourceViolation);
printf("CmdSecurityOptionConfig: Source ");
for (i = 0; i < SWI_SOURCE_INTRUDE_MAXOPT; i++) {
printf("Intrude[%d]=%d, ", i, sourceIntrusion[i]);
if (i == 2)
printf("\n");
}
printf("\n");
for (i = 0; i < SWI_SOURCE_VIOLATE_MAXOPT; i++) {
printf("Violate[%d]=%d, ", i, sourceViolation[i]);
if (i == 2)
printf("\n");
}
printf("\n");
}
/************************************************************************************/
/* CmdLearnTableRead: */
/************************************************************************************/
void CmdLearnTableRead(int argc, char **argv)
{
int accessControl, fidVal, retVal, i;
word portMapVal, entryStatus, infoCtrlAge;
int tmp[SWI_MACADDR_LENGTH];
word portMap[7];
byte macAddr[SWI_MACADDR_LENGTH];
// option description:
// accessControl: the MAC table search access control (s1..s8)
// portMap[]: the output port map (pd-d-d-d-d-d)
// fidVal: the FID value associated with the MAC table (f0..f15)
// macAddr[]: the 6-bytes MAC address ssociated with the learning table (%x-%x-%x-%x-%x-%x)
portMapVal = infoCtrlAge = 0;
for (i = 0; i < 7; i++) {
portMap[i] = 0;
}
// Get the access control item value.
sscanf(argv[1], "s%d", &accessControl);
if ((accessControl < 1) || (accessControl > 8)) {
printf("ArgErr: the access control must be in 1..8 !\n");
return;
}
// Get the port map
sscanf(argv[2], "p%d-%d-%d-%d-%d-%d", &portMap[0], &portMap[1], &portMap[2], &portMap[3], &portMap[4], &portMap[5]);
// Get the FID value.
sscanf(argv[3], "f%d", &fidVal);
if ((fidVal < 0) || (fidVal > 15)) {
printf("ArgErr: the FID must be in 0..15 !\n");
return;
}
if (sscanf(argv[4], "%x-%x-%x-%x-%x-%x", &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]) != SWI_MACADDR_LENGTH) {
printf("ArgErr: the MAC format must be like XX-XX-XX-XX-XX-XX !\n");
printf("MAC=%02x-%02x-%02x-%02x-%02x-%02x\n", tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]);
return;
}
for (i = 0; i < SWI_MACADDR_LENGTH; i++)
macAddr[i] = (byte)tmp[i];
printf("CmdLearnTableRead: Access=%d, fid=%d, MAC=%02x-%02x-%02x-%02x-%02x-%02x\n", accessControl, fidVal,
(word)macAddr[0], (word)macAddr[1], (word)macAddr[2], (word)macAddr[3], (word)macAddr[4], (word)macAddr[5]);
for (i = 0; i < SWI_MAX_PORT_NUMBER; i++) {
printf("Portmap[%d]=%d,", i, portMap[i]);
if (i == 2)
printf("\n");
}
printf("\n");
retVal = SWLearnTableRead(accessControl, portMap, &fidVal, macAddr, &entryStatus, &infoCtrlAge);
printf("RetLearnTable: Status=%#x, Portmap=%#x, FID=%d, MAC=%02x-%02x-%02x-%02x-%02x-%02x\n", entryStatus, portMap[6], fidVal,
(word)macAddr[0], (word)macAddr[1], (word)macAddr[2],(word) macAddr[3], (word)macAddr[4], (word)macAddr[5]);
switch (retVal) {
case SWI_COMMAND_ENTRY_FOUND:
printf("The learning table read is O.K. !\n");
break;
case SWI_ACCESS_ALLENTRY_USED:
printf("The learning table entries are full. !\n");
break;
case SWI_COMMAND_ENTRY_MISSED:
printf("The learning table entry is not found. !\n");
break;
default:
printf("The learning table read is failed !\n");
break;
}
}
/************************************************************************************/
/* CmdLearnTableWrite: */
/************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -