📄 igmpcon_cli.c
字号:
}
}
/*************************************************
Function: GetMaxGroupStat
Description: get max group statistic
Input: int time, int totalcount
Output:
Return:
Others:
*************************************************/
GroupStat *GetMaxGroupStat (int time, int totalcount)
{
int max, count;
GroupStat *ptmp, *ptmp2;
UINT groupaddress;
if ((time + totalcount) != 1)
return NULL;
max = 0;
count = groupstatcount;
ptmp = groupstatlist;
ptmp2 = ptmp;
while (ptmp && count)
{
count--;
if (time)
{
if (ptmp->totaltime > max && !ptmp->show)
{
max = ptmp->totaltime;
ptmp2 = ptmp;
}
}
if (totalcount)
{
if (ptmp->totalcount > max && !ptmp->show)
{
max = ptmp->totalcount;
ptmp2 = ptmp;
}
}
ptmp = ptmp->pNext;
}
if (!max)
{
return NULL;
}
else
{
ptmp2->show = 1;
return ptmp2;
}
}
/*time =1 以时间排序显示,count=1,以次数排序显示,不能同时为1*/
/*************************************************
Function:showstatbytime
Description: list group statistics sequencely by inpute parameters
Input:
Output:
Return:
Others:
*************************************************/
void showstatbytime (struct vty *vty, int time, int count)
{
GroupStat *ptmp;
int gcount;
int semstat;
semstat = semTake (semConStat, 1);
if (ERROR == semstat)
{
printf ("Take semstat error!\r\n");
semtakeerror++;
return;
}
if ((time + count) != 1)
{
semGive (semConStat);
return;
}
if (NULL == groupstatlist)
{
semGive (semConStat);
return;
}
while (ptmp = GetMaxGroupStat (time, count))
{
ShowGroupStat (ptmp->groupaddress, vty);
}
ptmp = groupstatlist;
gcount = groupstatcount;
while (gcount)
{
ptmp->show = 0;
gcount--;
ptmp = ptmp->pNext;
}
semGive (semConStat);
return;
}
/*************************************************
Function: InputPortCheck
Description: check inpute port is valid port or not
Input: char slot, char onu, char onuPort, struct vty *vty
Output:
Return: valid return 0, invalid return -1;
Others:
*************************************************/
int InputPortCheck (char slot, char onu, char onuPort, struct vty *vty)
{
if (slot > 0 && slot <= MAX_DOWN_SLOT + 2 && onu > 0 && onu <= MaxOnu)
{
return 0;
}
else
{
vty_out (vty, "Invalid input!\r\n");
return -1;
}
}
/*************************************************
Function: SetLeaveDelay
Description: set group leave delay time
Input: UINT groupaddress, short delay
Output:
Return:
Others:
*************************************************/
int SetLeaveDelay (UINT groupaddress, short delay)
{
GroupAuth *ptmp;
ptmp = (GroupAuth *) GetAuthGroup (groupaddress);
/*建立新的表项 */
if (NULL == ptmp)
{
printf ("\r\nAdd this group to profile first!\r\n");
return ERROR;
}
else
{
ptmp->leavedelay = delay;
}
return OK;
}
/*************************************************
Function: GetLeaveDelay
Description: get leave delay time by group address
Input: groupaddress
Output:
Return:
Others:
*************************************************/
int GetLeaveDelay (UINT groupaddress)
{
GroupAuth *ptmp;
ptmp = (GroupAuth *) GetAuthGroup (groupaddress);
if (NULL == ptmp)
return 0;
return ptmp->leavedelay;
}
/*************************************************
Function: GetGroupAddRang
Description: parse a groupaddress rang string, convert it to
uplimit address and low limit address
Input: char *add, UINT * max, UINT * min
Output: max is uplimit, min is low limit
Return:
Others:
*************************************************/
int GetGroupAddRang (char *add, UINT * max, UINT * min)
{
char firstadd[20];
char secadd[20];
char *p, *init;
struct in_addr gip1;
struct in_addr gip2;
int i, j;
UINT a, b;
memset (firstadd, 0, sizeof (firstadd));
memset (secadd, 0, sizeof (secadd));
init = add;
p = strchr (add, '-');
if (NULL == p)
{
inet_aton (add, &gip1);
*max = inet_addr (add);
*min = inet_addr (add);
if (-1 == CheckGroupAddress (add))
{
return ERROR;
}
}
else
{
i = 0;
while (add[i] != '-')
{
firstadd[i] = add[i];
i++;
}
i++;
j = 0;
while (add[i] != 0)
{
secadd[j] = add[i];
j++;
i++;
}
if (CheckGroupAddress (firstadd) == -1 ||
CheckGroupAddress (secadd) == -1)
{
return ERROR;
}
a = inet_addr (firstadd);
b = inet_addr (secadd);
if (a > b)
{
*max = a;
*min = b;
}
else
{
*max = b;
*min = a;
}
if ((*max - *min) > (MaxtTempGroup - 1))
return ERROR;
}
return OK;
}
/*************************************************
Function: GetProfliebyName
Description: get a profilne no. by its name
Input: char *name
Output:
Return: tmpno, or 0(wrong name)
Others:
*************************************************/
int GetProfliebyName (char *name)
{
int i, len, count;
char tmpno;
count = 0;
len = strlen (name);
for (i = 1; i <= MaxTemp; i++)
{
if (stricmp (profile[i].name, name) == 0)
{
return i;
}
}
return 0;
}
void groupband (char *groupadd)
{
char add[40];
UINT max, min;
GetGroupAddRang (groupadd, &max, &min);
printf ("max:%x, min:%x\r\n", max, min);
}
int GetVlanCount (void)
{
int count;
GroupAuth *ptmp;
int vlan[4096];
count = 0;
memset (vlan, 0, sizeof (vlan));
ptmp = authlist;
while (ptmp)
{
if (ptmp->vlanid && !vlan[ptmp->vlanid])
{
count++;
vlan[ptmp->vlanid] = 1;
}
ptmp = ptmp->pNext;
}
count++;
return count;
}
#define MaxPort 128
/*获取端口的字符串形式,port为输入数组首地址,str为输入*/
/*************************************************
Function: GetPortList
Description: convert a 2-dimension port table to a portlist string
Input: char *str, char *port
Output: portlist
Return:
Others: no use now
*************************************************/
void GetPortList (char *str, char *port)
{
int i, j, k;
char portmap[MAX_DOWN_SLOT * MaxPort];
char porttemp[MAX_DOWN_SLOT + 1][MaxPort + 1];
int count;
int first, last, fslot, fport, lslot, lport;
int flag = 0, check = 0;
char *p;
char *tmp[256];
memcpy (porttemp, port, sizeof (porttemp));
k = 0;
for (i = 1; i <= MAX_DOWN_SLOT; i++)
{
for (j = 1; j <= MaxPort; j++)
{
portmap[k] = porttemp[i][j];
if (portmap[k])
check = 1;
k++;
}
}
if (!check)
return;
i = 0;
count = MAX_DOWN_SLOT * MaxPort;
memset (tmp, 0, sizeof (tmp));
while (i < count)
{
if (portmap[i])
{
first = i;
for (;
((portmap[i + 1]) * (portmap[i])) &&
i < MAX_DOWN_SLOT * MaxPort; i++);
last = i;
fslot = (first / MaxPort) + 1;
fport = (first % MaxPort) + 1;
lslot = (last / MaxPort) + 1;
lport = (last % MaxPort) + 1;
if (fslot > 8)
{
fslot = fslot + 2;
}
if (lslot > 8)
{
lslot = lslot + 2;
}
if (!flag)
{
if (first == last)
{
sprintf ((char *) tmp, "%d:%d", fslot, fport);
}
else
{
sprintf ((char *) tmp, "%d:%d-%d:%d", fslot, fport, lslot,
lport);
}
flag = 1;
}
else
{
if (first == last)
{
sprintf ((char *) tmp, ",%d:%d", fslot, fport);
}
else
{
sprintf ((char *) tmp, ",%d:%d-%d:%d", fslot, fport, lslot,
lport);
}
}
strncat ((char *) str, (char *) tmp, strlen ((char *) tmp));
memset (tmp, 0, sizeof (tmp));
}
i++;
}
}
/*************************************************
Function: ShowRunOneProfile
Description:
Input: int tmpno, struct vty *vty
Output:
Return:
Others:
*************************************************/
void ShowRunOneProfile (int tmpno, struct vty *vty)
{
GroupAuth *ptmp;
UINT add[300];
UINT first, last;
char stat[300];
int i, j, count;
struct in_addr gip1, gip2;
char portlist[200];
char temp[MAX_DOWN_SLOT + 1][MaxPort + 1];
char ip[20], ip2[20];
if (!profile[tmpno].used)
return;
memset (temp, 0, sizeof (temp));
memset (portlist, 0, sizeof (portlist));
memset (add, 0, sizeof (add));
memset (stat, 0, sizeof (stat));
vty_out (vty, "create igmp profile %s\r\n", profile[tmpno].name);
ptmp = authlist;
while (ptmp)
{
if (ptmp->profile[tmpno])
{
InsertNodebySeq (300, ptmp->groupaddress, add);
}
ptmp = ptmp->pNext;
}
for (i = 0; add[i]; i++)
{
ptmp = (GroupAuth *) GetAuthGroup (add[i]);
stat[i] = ptmp->profile[tmpno];
}
if (bConDebug)
{
i = 0;
while (add[i] && i < 300)
{
/*printf ("add[%d] = %x %d\r\n ", i, add[i], stat[i]); */
i++;
}
}
i = 0;
while (add[i] && i < 300)
{
first = add[i];
for (; (add[i + 1] - add[i] == 1) && (stat[i + 1] == stat[i]); i++);
last = add[i];
gip1.s_addr = first;
gip2.s_addr = last;
inet_ntoa_b (gip1, ip);
inet_ntoa_b (gip2, ip2);
if (first == last)
{
if (stat[i] == 1)
{
vty_out (vty, "set igmp profile %s add %s normal\r\n",
profile[tmpno].name, ip);
}
else
{
vty_out (vty, "set igmp profile %s add %s preview\r\n",
profile[tmpno].name, ip);
}
}
else
{
if (stat[i] == 1)
{
vty_out (vty, "set igmp profile %s add %s-%s normal\r\n",
profile[tmpno].name, ip, ip2);
}
else
{
vty_out (vty, "set igmp profile %s add %s-%s preview\r\n",
profile[tmpno].name, ip, ip2);
}
}
i++;
}
}
/*************************************************
Function: InsertNodebySeq
Description: insert a node to an array by sequence, range is the array's space
Input:int range, UINT node, UINT * head
Output:
Return:
Others:
*************************************************/
int InsertNodebySeq (int range, UINT node, UINT * head)
{
int count;
UINT *p, *posision;
UINT a, b;
int i, j, k;
p = head;
if (*p == 0)
{
*p = node;
return OK;
}
j = 0;
count = range;
while (count && *p)
{
if (node <= *p)
{
posision = p;
p = head + range - 1;
for (i = 1; i < range - j; i++)
{
*p = *(p - 1);
p--;
}
*posision = node;
return OK;
}
p++;
count--;
j++;
}
if (*p == 0)
{
*p = node;
return OK;
}
return ERROR;
}
/*************************************************
Function: ShowRunOneGroup
Description:
Input:GroupAuth * auth, struct vty *vty
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -