📄 cli.c
字号:
void CmdLearnTableWrite(int argc, char **argv)
{
int accessControl, addrType, fidVal, retVal, i;
word infoCtrlAge;
word portMap[SWI_MAX_PORT_NUMBER];
byte macAddr[SWI_MACADDR_LENGTH];
int tmp[SWI_MACADDR_LENGTH];
// option description:
// accessControl: the MAC table create/overwrite/erase access control (-c/-o/-d)
// addrType: the MAC address type (-l/-s); -l: learning MAC, -s: static MAC
// infoCtrlAge: the control information (static MAC) or the value for the aging timer (i0xhhh)
// 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)
for (i = 0; i < SWI_MAX_PORT_NUMBER; i++) {
portMap[i] = 0;
}
// Get the MAC table create/overwrite/erase access control code.
if (strcmp(argv[1], "-c") == 0)
accessControl = 1;
else if (strcmp(argv[1], "-o") == 0)
accessControl = 2;
else if (strcmp(argv[1], "-d") == 0)
accessControl = 3;
else {
printf("ArgErr: the access control must be entered as -c/-o/-d !\n");
return;
}
// Get the MAC address type.
if (strcmp(argv[2], "-l") == 0)
addrType = SWI_DYNAMIC_MACADDR;
else if (strcmp(argv[2], "-s") == 0)
addrType = SWI_STATIC_MACADDR;
else {
printf("ArgErr: the MAC address type must be entered as -l/-s !\n");
return;
}
// Get the control information or the aging timer value
sscanf(argv[3], "i0x%x", &infoCtrlAge);
// Get the port map
sscanf(argv[4], "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[5], "f%d", &fidVal);
if ((fidVal < 0) || (fidVal > 15)) {
printf("ArgErr: the FID must be in 0..15 !\n");
return;
}
if (sscanf(argv[6], "%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("CmdLearnTableWrite: Access=%d, Type=%d, InfoCtrl=%#x, fid=%d, MAC=%02x-%02x-%02x-%02x-%02x-%02x\n",
accessControl, addrType, infoCtrlAge, 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 = SWLearnTableWrite(accessControl, addrType, infoCtrlAge, portMap, fidVal, macAddr);
switch (retVal) {
case SWI_COMMAND_ENTRY_FOUND:
printf("The learning table write 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 write is failed !\n");
break;
}
}
/************************************************************************************/
/* CmdIGMPConfig: */
/************************************************************************************/
void CmdIGMPConfig(int argc, char **argv)
{
int igmpEnable, queryInterval, robustVariable, ignoreCPUPort, i;
word routerPortMap[SWI_MAX_PORT_NUMBER];
// option description:
// igmpEnable: the hardware IGMP snooping function enable value (-i/-I)
// ignoreCPUPort: the hardware IGMP packet ignore CPU port <-c/-C>
// queryInterval: the Query_Interval value for the hardware IGMP snooping (q0..q255)
// robustVariable: the Robust_Variable value for the hardware IGMP snooping (r1..r3)
// routerPortMap[]: the default router port map for the hardware IGMP snooping (pd-d-d-d-d-d)
for (i = 0; i < SWI_MAX_PORT_NUMBER; i++)
routerPortMap[i] = 0;
// Get the hardware IGMP snooping function enable value.
if (strcmp(argv[1], "-i") == 0)
igmpEnable = 1;
else if (strcmp(argv[1], "-I") == 0)
igmpEnable = 0;
else {
printf("ArgErr: the hardware IGMP snooping enable must be as -i/-I !\n");
return;
}
// Get the hardware IGMP packet ignore CPU port value.
if (strcmp(argv[2], "-c") == 0)
ignoreCPUPort = 1;
else if (strcmp(argv[2], "-C") == 0)
ignoreCPUPort = 0;
else {
printf("ArgErr: the hardware IGMP packet ignore CPU port must be as -c/-C !\n");
return;
}
// Get the Query_Interval value for the hardware IGMP snooping.
sscanf(argv[3], "q%d", &queryInterval);
if ((queryInterval < 0) || (queryInterval > 255)) {
printf("ArgErr: the Query_Interval of IGMP must be in 0..255 !\n");
return;
}
// Get the Robust_Variable value for the hardware IGMP snooping.
sscanf(argv[4], "r%d", &robustVariable);
if ((robustVariable < 1) || (robustVariable > 3)) {
printf("ArgErr: the Robust_Variable of IGMP must be in 1..3 !\n");
return;
}
// Get the default router port map for the hardware IGMP snooping.
if (argc > 5)
sscanf(argv[5], "p%d-%d-%d-%d-%d-%d", &routerPortMap[0], &routerPortMap[1], &routerPortMap[2],
&routerPortMap[3], &routerPortMap[4], &routerPortMap[5]);
SWIGMPConfig(igmpEnable, ignoreCPUPort, queryInterval, robustVariable, routerPortMap);
printf("CmdIGMPConfig: igmpEn=%d, ignCPU=%d, QI=%d, RV=%d\n", igmpEnable, ignoreCPUPort, queryInterval, robustVariable);
for (i = 0; i < SWI_MAX_PORT_NUMBER; i++) {
printf("portMap[%d]=%d,", i, routerPortMap[i]);
if (i == 2)
printf("\n");
}
printf("\n");
}
/************************************************************************************/
/* CmdIGMPOptConfig: */
/************************************************************************************/
void CmdIGMPOptConfig(int argc, char **argv)
{
int igmpOptItem;
int igmpOptVal;
// option description:
// igmpOptItem: the hardware IGMP snooping option item number (0..8)
// 0: Trap IGMP_IP packet, 1: IGMP packet as Cross_VLAN packet, 2: IGMP packet priority enable
// 3: IGMP packet priority, 4: IGMP packet transmission TAG handle, 5: IGMP packet action,
// 6: Additional IGMP control, 7: Source Violation over IGMP, 8: Source Violation over Default
// optionValue: the hardware IGMP snooping option value (v0/1 or v0..v3 or v0..v2)
// Get the option item number.
sscanf(argv[1], "%d", &igmpOptItem);
if ((igmpOptItem < 0) || (igmpOptItem > 8)) {
printf("ArgErr: the IGMP option item number must be in 0..8 !\n");
return;
}
// Get the option value.
sscanf(argv[2], "v%d", &igmpOptVal);
printf("CmdIGMPOptConfig: igmpOpt[%d]=%d\n", igmpOptItem, igmpOptVal);
if ((igmpOptItem > 2) && (igmpOptItem < 6)) {
if ((igmpOptVal < 0) || (igmpOptVal > 3)) {
if (igmpOptItem == 3)
printf("ArgErr: the IGMP packet priority must be in 0..3 !\n");
else if (igmpOptItem == 4)
printf("ArgErr: the IGMP packet transmission TAG handle must be in 0..3 !\n");
else
printf("ArgErr: the IGMP control packet action must be in 0..3 !\n");
return;
}
} else if (igmpOptItem == 6) {
if ((igmpOptVal < 0) || (igmpOptVal > 2)) {
printf("ArgErr: the IGMP additional control must be in 0..2 !\n");
return;
}
} else {
if ((igmpOptVal < 0) || (igmpOptVal > 1)) {
printf("ArgErr: the IGMP option must be as 0 or 1 !\n");
return;
}
}
SWIGMPOptConfig(igmpOptItem, igmpOptVal);
}
/************************************************************************************/
/* CmdIGMPTableRead: */
/************************************************************************************/
void CmdIGMPTableRead(int argc, char **argv)
{
word portMapVal, entryState;
int retVal, entryIndex;
byte macAddr[SWI_IGMP_MACADDR_LENGTH];
// option description:
// entryIndex: the index of the IGMP membership table (d: 0..31)
// Get the IGMP table entry value.
sscanf(argv[1], "%d", &entryIndex);
if ((entryIndex < 0) || (entryIndex > 31)) {
printf("ArgErr: the index of the IGMP membership table must be in 0..31 !\n");
return;
}
retVal = SWIGMPTableRead(entryIndex, &entryState, &portMapVal, macAddr);
printf("CmdIGMPTableRead: entry[%d], State=%#x, portMap=%#x, MAC=%02x-%02x-%02x\n",entryIndex, entryState,
portMapVal, (word)macAddr[0], (word)macAddr[1], (word)macAddr[2]);
switch (retVal) {
case SWI_COMMAND_ENTRY_FOUND:
printf("The IGMP table read is O.K. !\n");
break;
case SWI_ACCESS_ALLENTRY_USED:
printf("The IGMP table entries are full. !\n");
break;
case SWI_COMMAND_ENTRY_MISSED:
printf("The IGMP table entry is not found. !\n");
break;
default:
printf("The IGMP table read is failed !\n");
break;
}
}
/************************************************************************************/
/* CmdIGMPTableWrite: */
/************************************************************************************/
void CmdIGMPTableWrite(int argc, char **argv)
{
int entryIndex, retVal, i;
int portMap[SWI_MAX_PORT_NUMBER];
// option description:
// entryIndex: the index of the IGMP membership table (d: 0..31)
// portMap[]: the output port map (pd-d-d-d-d-d)
for (i = 0; i < SWI_MAX_PORT_NUMBER; i++) {
portMap[i] = 0;
}
// Get the IGMP table entry value.
sscanf(argv[1], "%d", &entryIndex);
if ((entryIndex < 0) || (entryIndex > 31)) {
printf("ArgErr: the index of the IGMP membership table must be in 0..31 !\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]);
retVal = SWIGMPTableWrite(entryIndex, portMap);
printf("CmdIGMPTableWrite: entry[%d]\n",entryIndex);
for (i = 0; i < SWI_MAX_PORT_NUMBER; i++) {
printf("portMap[%d]=%d,", i, portMap[i]);
if (i == 2)
printf("\n");
}
printf("\n");
switch (retVal) {
case SWI_COMMAND_ENTRY_FOUND:
printf("The IGMP table write is O.K. !\n");
break;
case SWI_ACCESS_ALLENTRY_USED:
printf("The IGMP table entries are full. !\n");
break;
case SWI_COMMAND_ENTRY_MISSED:
printf("The IGMP table entry is not found. !\n");
break;
default:
printf("The IGMP table write is failed !\n");
break;
}
}
/************************************************************************************/
/* CmdGetPortCounter: get the statistics counters of the port */
/************************************************************************************/
void CmdGetPortCounter(int argc, char **argv)
{
int i, port_no;
// option description:
// port_no: the port number (0..5)
// clearCounter: the option for the clear counter (-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;
}
if (argc > 2) {
// Get the option for the clear counter
if (strcmp(argv[2], "-c") == 0) {
i = SWResetPortCounter(port_no); // add - 06/16/05,bolo
if (i) {
printf("The port[%d] counters read is failed !\n",port_no);
return;
}
} else {
printf("ArgErr: the clear counter option must be as -c !\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -