📄 igmpcon_cli.c
字号:
Output:
Return:
Others: no use now
*************************************************/
void ShowRunOneGroup (GroupAuth * auth, struct vty *vty)
{
GroupAuth *ptmp;
struct in_addr gip;
int flag = 0;
char ip[20];
ptmp = auth;
gip.s_addr = ptmp->groupaddress;
inet_ntoa_b (gip, ip);
/*组播VLAN */
if (gEnableCrossVlan && ptmp->vlanid != 0)
{
vty_out (vty, "add igmp group %s vlan %d\r\n", ip, ptmp->vlanid);
flag = 1;
}
/*节目源带宽 */
if (ptmp->bandwidth)
{
vty_out (vty, "set igmp group %s bandwidth %d\r\n", ip,
ptmp->bandwidth);
flag = 1;
}
/*推迟离开 */
if (ptmp->leavedelay)
{
vty_out (vty, "set igmp group %s delayleave %d\r\n", ip,
ptmp->leavedelay);
flag = 1;
}
/*预览参数 */
if (ptmp->preCount != previewcount || ptmp->preInterval != previewinterval
|| ptmp->preReset != previewresettime || ptmp->preTime != previewtime ||
ptmp->pretotaltime != previewTotalTime)
{
vty_out (vty,
"set igmp preview count %d during %d interval %d reset %d total %d %s\r\n",
ptmp->preCount, ptmp->preTime, ptmp->preInterval, ptmp->preReset,
ptmp->pretotaltime, ip);
flag = 1;
}
if (flag)
vty_out (vty, "\r\n");
}
/*************************************************
Function: ShowRunOneGroup2
Description:
Input: GroupAuth * auth, struct vty *vty
Output:
Return:
Others:
*************************************************/
void ShowRunOneGroup2 (GroupAuth * auth, struct vty *vty)
{
GroupAuth *ptmp;
struct in_addr gip;
int flag = 0;
char ip[20];
char temp[150];
char temp2[20];
ptmp = auth;
gip.s_addr = ptmp->groupaddress;
inet_ntoa_b (gip, ip);
memset (temp, 0, sizeof (temp));
/*节目源带宽 */
if (ptmp->bandwidth)
{
memset (temp2, 0, sizeof (temp2));
sprintf (temp2, "bandwidth %d ", ptmp->bandwidth);
strcat (temp, temp2);
}
/*推迟离开 */
if (ptmp->leavedelay)
{
memset (temp2, 0, sizeof (temp2));
sprintf (temp2, "leave_delay %d ", ptmp->leavedelay);
strcat (temp, temp2);
}
/*组播VLAN */
if (ptmp->vlanid != 0)
{
memset (temp2, 0, sizeof (temp2));
sprintf (temp2, "vlan %d ", ptmp->vlanid);
strcat (temp, temp2);
}
/*上行VLAN */
if (ptmp->uplink_vlan != 0)
{
memset (temp2, 0, sizeof (temp2));
sprintf (temp2, "uplink_vlan %d ", ptmp->uplink_vlan);
strcat (temp, temp2);
}
if (temp[0] != 0)
vty_out (vty, "set igmp group %s %s\r\n", ip, temp);
/*预览参数 */
if (ptmp->preCount != previewcount || ptmp->preInterval != previewinterval
|| ptmp->preReset != previewresettime || ptmp->preTime != previewtime ||
ptmp->pretotaltime != previewTotalTime)
{
vty_out (vty,
"set igmp preview count %d during %d interval %d reset %d total %d %s\r\n",
ptmp->preCount, ptmp->preTime, ptmp->preInterval, ptmp->preReset,
ptmp->pretotaltime, ip);
flag = 1;
}
}
/*************************************************
Function: ShowRunPort
Description:
Input: struct vty *vty
Output:
Return:
Others: no use now
*************************************************/
void ShowRunPort (struct vty *vty)
{
int i, j, k, count;
/*端口可控 */
for (i = 1; i <= MAX_DOWN_SLOT; i++)
{
for (j = 1; j <= MaxOnu; j++)
{
for (k = 1; k <= MaxOnuPort; k++)
{
/*端口可控 */
if (portstatlist[i][j][k].control != 0)
{
vty_out (vty, "set igmp port %d %d %d control enable\r\n",
i, j, k);
}
/*端口在线组数 */
if (portstatlist[i][j][k].gouplimit != 32)
{
vty_out (vty, "set igmp port %d %d %d group limit %d\r\n",
i, j, k, portstatlist[i][j][k].gouplimit);
}
/*端口带宽 */
if (portstatlist[i][j][k].bandwidth != 0)
{
vty_out (vty, "set igmp port %d %d %d bandwidth %d\r\n", i,
j, k, portstatlist[i][j][k].bandwidth);
}
/*vlan剥离 */
if (portstatlist[i][j][k].vlanpeer != 0)
{
vty_out (vty, "set igmp port %d %d %d vlan peel enable\r\n",
i, j, k);
}
/*模版绑定 */
if (portstatlist[i][j][k].tmpno != 0)
{
vty_out (vty,
"set igmp port %d %d %d attach profile %s\r\n", i, j, k,
profile[portstatlist[i][j][k].tmpno].name);
}
}
}
}
}
/*************************************************
Function: ShowRunPort2
Description:
Input: struct vty *vty
Output:
Return:
Others:
*************************************************/
void ShowRunPort2 (struct vty *vty)
{
int slot, onu, port, count;
int start, end;
int use = 0;
char temp[100];
char temp2[20];
memset (temp, 0, sizeof (temp));
/*端口可控 */
for (slot = 1; slot <= MAX_DOWN_SLOT; slot++)
{
for (onu = 1; onu <= MaxOnu; onu++)
{
if (!onulist[slot][onu].type || !onulist[slot][onu].used)
continue;
if (onulist[slot][onu].flag_ftth)
{
start = onulist[slot][onu].igmp_port;
end = start;
}
else
{
start = 1;
end = onulist[slot][onu].total_port;
}
for (port = start; port <= end; port++)
{
memset (temp, 0, sizeof (temp));
/*端口可控 */
if (portstatlist[slot][onu][port].control != 0)
{
strcat (temp, "control enable ");
}
/*端口带宽 */
if (portstatlist[slot][onu][port].bandwidth != 0)
{
memset (temp2, 0, sizeof (temp2));
sprintf (temp2, "bandwidth %d ",
portstatlist[slot][onu][port].bandwidth);
strcat (temp, temp2);
}
/*leave mode */
if (portstatlist[slot][onu][port].fast_leave_state == 0)
{
strcat (temp, "leave non_fast ");
}
/*vlan剥离 */
if (portstatlist[slot][onu][port].vlanpeer != 0)
{
strcat (temp, "vlan_strip enable ");
}
/*端口在线组数 */
if (portstatlist[slot][onu][port].gouplimit != 32)
{
memset (temp2, 0, sizeof (temp2));
sprintf (temp2, "max_group %d ",
portstatlist[slot][onu][port].gouplimit);
strcat (temp, temp2);
}
/*模版绑定 */
if (portstatlist[slot][onu][port].tmpno != 0)
{
memset (temp2, 0, sizeof (temp2));
sprintf (temp2, "profile %s ",
profile[portstatlist[slot][onu][port].tmpno].name);
strcat (temp, temp2);
}
if (temp[0] != 0)
{
vty_out (vty, "set igmp port %d %d %d %s\r\n",
translateslot_out (slot), onu, port, temp);
}
}
}
}
}
/*************************************************
Function: ShowRunIgmpCon
Description: configurationg of igmp proxy and igmp control module
Input: struct vty *vty
Output:
Return: succes 0, error -1;
Others:
*************************************************/
int ShowRunIgmpCon (struct vty *vty)
{
int i, j, k;
GroupAuth *ptmp;
vty_out (vty, "!IGMP config----------------------------------------\r\n");
if (bConDebug)
vty_out (vty, "debug on\r\n");
else
vty_out (vty, "debug off\r\n");
showrun_igmp_mode (vty);
/*IGMP PROXY配置 */
ShowRunIgmpProxy (vty);
if (global_vlan != DefaultVlan)
{
vty_out (vty, "set igmp vlan %d\r\n", global_vlan);
}
if (uplink_vlan_enable)
{
vty_out (vty, "set igmp uplink vlan enable\r\n");
}
if (RecordHolding != 10)
{
vty_out (vty, "set igmp record time %d\r\n", RecordHolding);
}
if (RecordIgnore)
{
vty_out (vty, "set igmp record ignore %d\r\n", RecordIgnore);
}
if (MaxUpBandwidth)
{
vty_out (vty, "set igmp max bandwidth %d\r\n", MaxUpBandwidth);
}
vty_out (vty,
"set igmp preview count %d during %d interval %d reset %d total %d\r\n",
previewcount, previewtime, previewinterval, previewresettime,
previewTotalTime);
vty_out (vty,
"\r\n!IGMP profile config----------------------------------------\r\n");
for (i = 1; i <= MaxTemp; i++)
{
ShowRunOneProfile (i, vty);
if (profile[i].used)
vty_out (vty, "\r\n");
}
vty_out (vty,
"\r\n!IGMP port config ----------------------------------------\r\n");
/*ShowRunPort (vty); */
ShowRunPort2 (vty);
vty_out (vty,
"\r\n!IGMP group config ----------------------------------------\r\n");
ptmp = authlist;
while (ptmp)
{
ShowRunOneGroup2 (ptmp, vty);
ptmp = ptmp->pNext;
}
auto_upload_showrun (vty);
vty_out (vty,
"\r\n!end of IGMP config ----------------------------------------\r\n");
return 0;
}
/***************************************************
函数名称:stricmp
函数功能:字符串比较函数(不区分大小写)
输入参数:s1 字符串1
s2 字符串2
返回值: 0 表示相同
非0表示不同
***************************************************/
static int stricmp (char *s1, char *s2)
{
int k = 0;
char str1[255];
char str2[255];
if ((strlen (s1) > 254) || (strlen (s2) > 254) || (strlen (s1) == 0) ||
(strlen (s2) == 0))
{
return ERROR;
}
strcpy (str1, s1);
strcpy (str2, s2);
while (str1[k])
{
str1[k] = tolower (str1[k]);
k++;
}
k = 0;
while (str2[k])
{
str2[k] = tolower (str2[k]);
k++;
}
k = strcmp (str1, str2);
return k;
}
/*************************************************
Function: GetCurrGroupCount
Description:
Input:
Output:
Return: current online group count
Others:
*************************************************/
int GetCurrGroupCount (void)
{
GroupInfo *ptmp;
int count = 0;
ptmp = infolist;
if (NULL == ptmp)
count = 0;
while (ptmp)
{
if (ptmp->groupaddress)
count++;
ptmp = ptmp->pNext;
}
return count;
}
/*************************************************
Function: set_igmp_global_vlan
Description:
Input: unsigned short vlanid
Output:
Return:
Others:
*************************************************/
int set_igmp_global_vlan (unsigned short vlanid)
{
short prevlan;
prevlan = global_vlan;
if (vlanid == 0)
vlanid = DefaultVlan;
global_vlan = vlanid;
return 0;
}
/*************************************************
Function: set_igmpMulticastVlanVid
Description:
Input: USHORT vlanid, char *vlanport
Output:
Return:
Others:
*************************************************/
int set_igmpMulticastVlanVid (USHORT vlanid, char *vlanport)
{
int pregloblevlan;
int i, j;
int exist = 0;
if (vlanid == 0)
{
vlanid = DefaultVlan;
}
pregloblevlan = global_vlan;
if ((vlanid > 4085 && vlanid != DefaultVlan) || vlanid < 1)
{
printf ("\r\nInput invalid VLAN tag\r\n");
return -1;
}
/* 在多组播VLAN模式下 */
if (gEnableCrossVlan)
{
/*跨VLAN 模式下,单播不能与组播VLAN相同 */
if (vlanid != DefaultVlan)
{
if (is_vlan_exist (vlanid))
{
printf ("\r\nVLAN %d is already exist!\r\n", vlanid);
return ERROR;
}
}
if (global_vlan != DefaultVlan)
{
if (delete_igmp_vlan (global_vlan) < 0)
{
printf ("\r\nDelete previous multicast vlan failed\r\n");
return -1;
}
}
if (vlanid != DefaultVlan)
{
if (create_igmp_vlan (vlanid) < 0)
{
printf ("\r\nCreate new multicast vlan failed\r\n");
return -1;
}
}
global_vlan = vlanid;
return OK;
}
/*单组播VLAN 模式下(不跨VLAN),必须找到一个单播VLAN,否则配置失败返回 */
#if 0
if (vlanid != DefaultVlan)
{
if (!is_vlan_exist (vlanid))
{
printf ("\r\nNo such unicast VLAN %d exist!\r\n", vlanid);
return ERROR;
}
}
#endif
global_vlan = vlanid;
return OK;
}
/*************************************************
Function: is_valid_igmp_port
Description:
Input: char slot, unsigned char onu, unsigned char port
Output:
Return:
Others:
*************************************************/
BOOL is_valid_igmp_port (char slot, unsigned char onu, unsigned char port)
{
/*printf ("%d:%d:%d, type:%d, igmpport:%d, totalport:%d, ftth:%d\r\n", slot, onu, port, onulist[slot][onu].type,
onulist[slot][onu].igmp_port,onulist[slot][onu].total_port,onulist[slot][onu].flag_ftth); */
if (slot > MAX_DOWN_SLOT)
return FALSE;
if (onulist[slot][onu].type == 0)
return FALSE;
if (onulist[slot][onu].flag_ftth && onulist[slot][onu].igmp_port != port)
return FALSE;
if (!onulist[slot][onu].flag_ftth && onulist[slot][onu].total_port < port)
return FALSE;
return TRUE;
}
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -