⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 igmpcon_cli.c

📁 igmp for switch in vxworks
💻 C
📖 第 1 页 / 共 5 页
字号:

	if (act == 1 && NULL == ptmp && Totalauthgroup == MaxGroup)
	{
		printf ("\r\nERROR, Totalauthgroup is %d \r\n", MaxGroup);
		return ERROR;
	}

	/*增加模版 */
	/*该组不存在于链表中,需创建 */
	if (act == 1)
	{
		profile[tmpno].used = 1;
		if (NULL == ptmp)
		{
			if (profile[tmpno].Groupcount == MaxtTempGroup)
			{
				printf ("\r\nExcess max profile group count,Error!\r\n");
				return ERROR;
			}
			ptmp = CreateAuthGroup (groupaddress);
			if (NULL == ptmp)
			{
				printf ("CreateAuthGroup: malloc failed\r\n");
				return ERROR;
			}

			AddAuthGroupToList (ptmp);
			ptmp->profile[tmpno] = state;
			ptmp->profile[0] = 1;
			profile[tmpno].Groupcount++;
		}
		/*改组已经存在与链表中,但需要更改组和所绑定端口的状态 */
		else
		{
			if (ptmp->profile[tmpno] == state)
				return OK;

			if (!ptmp->profile[tmpno] &&
				profile[tmpno].Groupcount == MaxtTempGroup)
			{
				printf ("\r\nExcess max profile group count,Error!\r\n");
				return ERROR;
			}

			if (!ptmp->profile[tmpno])
			{
				ptmp->profile[0]++;
				profile[tmpno].Groupcount++;
			}
			ptmp->profile[tmpno] = state;
		}
	}

	/*删除组 */
	else
	{
		if (NULL == ptmp)
			return ERROR;

		if (state != ptmp->profile[tmpno])
			return ERROR;

		if (!ptmp->profile[tmpno])
		{
			printf ("\r\nNo such group \r\n");
			return ERROR;
		}

		ptmp->profile[tmpno] = 0;
		profile[tmpno].Groupcount--;
		ptmp->profile[0]--;

		/*不存在任何模版时,需要删除该组 */
		if (ptmp->profile[0] == 0)
		{
			if (ptmp->vlanid && ptmp->vlanid != global_vlan)
				DelGroupVlan (ptmp->groupaddress);
			DelAuthGroupFromList (ptmp);
		}
	}

	/*更新模板内容到端口 */
	return OK;
}

/*************************************************
  Function:       
  Description:   
  Input:         	 
  Output:         
  Return:         
  Others:        
*************************************************/
int addGroup2Profile (int tmpno, UINT groupaddress, char state)
{
	int i, j;
	GroupAuth *ptmp;
	GroupInfo *onlinegroup;

	ptmp = (GroupAuth *) GetAuthGroup (groupaddress);

	/*增加模版 */

	/*该组不存在于链表中,需创建 */

	profile[tmpno].used = 1;
	if (NULL == ptmp)
	{
		if (Totalauthgroup == MaxGroup)
		{
			return ERROR;
		}

		if (profile[tmpno].Groupcount == MaxtTempGroup)
		{
			printf ("\r\nExcess max profile group count,Error!\r\n");
			return ERROR;
		}
		ptmp = CreateAuthGroup (groupaddress);
		if (NULL == ptmp)
		{
			printf ("CreateAuthGroup: malloc failed\r\n");
			return ERROR;
		}
		ptmp->profile[tmpno] = state;
		AddAuthGroupToList (ptmp);
		ptmp->profile[tmpno] = state;
		ptmp->profile[0] = 1;
		profile[tmpno].Groupcount++;
	}
	/*改组已经存在与链表中,但需要更改组和所绑定端口的状态 */
	else
	{
		if (ptmp->profile[tmpno] == state)
			return OK;

		if (!ptmp->profile[tmpno] && profile[tmpno].Groupcount == MaxtTempGroup)
		{
			printf ("\r\nExcess max profile group count,Error!\r\n");
			return ERROR;
		}

		if (!ptmp->profile[tmpno])
		{
			ptmp->profile[0]++;
			profile[tmpno].Groupcount++;
		}
		ptmp->profile[tmpno] = state;
	}
	return OK;
}

/*************************************************
  Function: DelConTemp      
  Description:  remove an igmp profile, if there are some ports 
            attatched to such profile, they should deattach ti first
  Input: tmpno        	 
  Output:         
  Return: success 0, error -1;        
  Others:        
*************************************************/
int DelConTemp (int tmpno)
{
	GroupAuth *ptmp, *ptmp2;
	int i, j;

	/*模版中的组如果当前在线,则不能删除 */
	/*ptmp = authlist;
	   while (ptmp)
	   {
	   if (ptmp->active && ptmp->profile[tmpno])
	   {
	   printf ("\r\nLeave all groups in this profile first!\r\n");
	   return ERROR;
	   }
	   ptmp = ptmp->pNext;
	   } */

	ptmp = authlist;
	ptmp2 = ptmp;
	while (ptmp)
	{
		if (ptmp->profile[tmpno])
		{
			ptmp->profile[tmpno] = 0;

			ptmp->profile[0]--;
			/*改组不存在任何模版,删除 */
			if (ptmp->profile[0] == 0)
			{
				ptmp2 = ptmp;
				ptmp = ptmp->pNext;
				if (ptmp2->vlanid && ptmp2->vlanid != global_vlan)
					DelGroupVlan (ptmp2->groupaddress);
				DelAuthGroupFromList (ptmp2);
				continue;
			}
		}
		ptmp = ptmp->pNext;
	}

	profile[tmpno].Groupcount = 0;
	memset (profile[tmpno].name, 0, sizeof (profile[tmpno].name));
	profile[tmpno].used = 0;

	return OK;
}

/*************************************************
  Function: DelConTemp      
  Description:  remove an igmp profile, if there are some ports 
            attatched to such profile, they should deattach ti first
  Input: tmpno        	 
  Output:         
  Return: success 0, error -1;        
  Others: no use now       
*************************************************/

int DelConTempGroup (int tmpno)
{
	GroupAuth *ptmp, *ptmp2;
	int i, j;

	ptmp = authlist;
	ptmp2 = ptmp;
	while (ptmp)
	{
		if (ptmp->profile[tmpno])
		{
			ptmp->profile[tmpno] = 0;

			ptmp->profile[0]--;
			/*改组不存在任何模版,删除 */
			if (ptmp->profile[0] == 0)
			{
				ptmp2 = ptmp;
				ptmp = ptmp->pNext;
				if (ptmp2->vlanid && ptmp2->vlanid != global_vlan)
					DelGroupVlanbySnmp (ptmp2);
				DelAuthGroupFromList (ptmp2);
				continue;
			}
		}
		ptmp = ptmp->pNext;
	}

	profile[tmpno].Groupcount = 0;
	return OK;
}

/*************************************************
  Function:  AddPort2Temp     
  Description: 将端口添加到配置模板中,tmpno =0表示将端口从模版删除  
  Input: int tmpno, UCHAR slot, UCHAR onu, UCHAR onuPort        	 
  Output:   none      
  Return:   none      
  Others:        
*************************************************/
void AddPort2Temp (int tmpno, UCHAR slot, UCHAR onu, UCHAR onuPort)
{

	/*tmpno = 0表示从之前的模版删除 */
	portstatlist[slot][onu][onuPort].tmpno = tmpno;

	SendCfgPkt (port2groupmsg, slot, onu, onuPort, 0);
	return;
}

/*************************************************
  Function:  ShowOneTemp     
  Description:   show onu igmp profile
  Input:   int tmpno, struct vty *vty      	 
  Output:         
  Return:         
  Others:        
*************************************************/
void ShowOneTemp (int tmpno, struct vty *vty)
{
	int i, j, k;
	int count;
	GroupAuth *ptmp;
	struct in_addr gip;
	char ip[20];

	if (!tmpno)
	{
		return;
	}

	ShowOneProfile (tmpno, vty);
	vty_out (vty, "Binded Ports:");
	count = 0;
	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].tmpno == tmpno)
				{
					count++;
					if ((count % 8) == 1)
					{
						vty_out (vty, "\r\n");
					}
					if (i > 8)
					{
						vty_out (vty, "%2d:%2d:%2d, ", i + 2, j, k);
					}
					else
					{
						vty_out (vty, "%2d:%2d:%2d, ", i, j, k);
					}
				}
			}
		}
	}
	vty_out (vty, "\r\n");
}

/*************************************************
  Function:   ShowOneProfile    
  Description: show igmp profile by tmpno, only show groups  
  Input: int tmpno, struct vty *vty        	 
  Output:   none      
  Return:   none      
  Others:        
*************************************************/
void ShowOneProfile (int tmpno, struct vty *vty)
{
	int i, j;
	int count;
	UINT normal[MaxtTempGroup + 10], pre[MaxtTempGroup + 10];
	char str[4000];
	GroupAuth *ptmp;

	i = 0;
	j = 0;
	memset (normal, 0, sizeof (normal));
	memset (pre, 0, sizeof (pre));
	memset (str, 0, sizeof (str));
	count = 0;
	ptmp = authlist;
	while (ptmp)
	{
		if (ptmp->profile[tmpno])
		{

			count++;
			if (ptmp->profile[tmpno] == 1)
			{
				normal[i] = ptmp->groupaddress;
				i++;
			}
			else
			{
				pre[j] = ptmp->groupaddress;
				j++;
			}
		}
		ptmp = ptmp->pNext;
	}

	memset (str, 0, sizeof (str));
	GetGroupString (str, normal, 4000);
	if (strlen (str))
	{
		vty_out (vty, "Normal Groups:\r\n");
		vty_out (vty, "%s\r\n", str);
	}

	memset (str, 0, sizeof (str));
	GetGroupString (str, pre, 4000);
	if (strlen (str))
	{
		vty_out (vty, "Preview Groups:\r\n");
		vty_out (vty, "%s\r\n", str);
	}
	/*vty_out (vty, "Binded Ports:\r\n");
	   memset (str, 0, sizeof (str));
	   GetPortList (str, profile[tmpno].member); 
	   vty_out (vty, "%s\r\n", str); */
}

/*显示模板*/

/*************************************************
  Function:    ShowTemplate   
  Description:   
  Input:         	 
  Output:         
  Return:         
  Others:        
*************************************************/
void ShowTemplate (int tmpno, struct vty *vty)
{
	int i, j;

	/*显示全部模板 */
	if (tmpno == 0)
	{
		for (i = 1; i <= MaxTemp; i++)
		{
			if (profile[i].used)	/*if (ConTemplate[i][0].groupaddress) modified by aibin 20060615 */
			{
				vty_out (vty,
					"*************************Profile NO.%2d*************************\r\n",
					i);
				vty_out (vty, "Name :  %s\r\n", profile[i].name);
				ShowOneTemp (i, vty);
				vty_out (vty,
					"*****************************E n d******************************\r\n");
			}
		}
	}
	/*显示指定的模板 */
	else
	{
		vty_out (vty,
			"*************************Profile NO.%2d*************************\r\n",
			tmpno);
		vty_out (vty, "Name :  %s\r\n", profile[tmpno].name);
		ShowOneTemp (tmpno, vty);
		vty_out (vty,
			"*****************************E n d******************************\r\n");
	}

}

/*检测组播地址的合法性,合法返回0,否则-1*/

/*************************************************
  Function:    CheckGroupAddress   
  Description: check a groupaddress whether a valid group  
  Input:         	 
  Output:         
  Return:         
  Others:   none-multicast address and protocol reserve address is invalid address     
*************************************************/
int CheckGroupAddress (char *address)
{
	struct in_addr gip;
	UINT a;

	a = inet_addr (address);
	inet_aton (address, &gip);
	if (a <= 0xe00000ff || a > 0xefffffff)
	{
		return -1;
	}
	return OK;
}

/*************************************************
  Function:  ShowPortStat     
  Description: 显示端口统计  
  Input:  USHORT slot, USHORT onu, USHORT onuPort, struct vty *vty       	 
  Output:         
  Return:         
  Others:        
*************************************************/
void ShowPortStat (USHORT slot, USHORT onu, USHORT onuPort, struct vty *vty)
{
	char max[10], time[10], every[10];
	int count;
	int everage;
	int slotnew;

	if (slot > MAX_DOWN_SLOT || slot < 1 || onu < 1 || onu > MaxOnu)
	{
		return;
	}

	slotnew = slot;
	if (slotnew > 8)
	{
		slotnew = slotnew + 2;
	}
	memset (max, 0, 10);
	memset (time, 0, 10);
	memset (every, 0, 10);
	count = portstatlist[slot][onu][onuPort].totalcount;
	TimeConvert (portstatlist[slot][onu][onuPort].maxtime, max);
	TimeConvert (portstatlist[slot][onu][onuPort].totaltime, time);
	TimeConvert ((portstatlist[slot][onu][onuPort].totaltime / count), every);
	vty_out (vty, "%2d:%2d:%2d        %-18d%-18s%-18s%-18s\r\n", slotnew, onu,
		onuPort, count, time, max, every);
}

/*************************************************
  Function: ShowGroupStat      
  Description: 显示组统计  
  Input:  UINT groupaddress, struct vty *vty       	 
  Output:         
  Return:         
  Others:        
*************************************************/
void ShowGroupStat (UINT groupaddress, struct vty *vty)
{
	int count = 0;
	GroupStat *ptmp;
	int statcount;
	char max[10], time[10], every[10], prev[10];
	struct in_addr gip;
	char ip[20];

	ptmp = groupstatlist;
	statcount = groupstatcount;
	/*显示全部组统计信息 */
	if (groupaddress == 0)
	{
		while (statcount)
		{
			memset (max, 0, 9);
			memset (time, 0, 9);
			memset (every, 0, 9);
			TimeConvert (ptmp->totaltime, time);
			TimeConvert (ptmp->previewtime, prev);
			TimeConvert (ptmp->maxtime, max);
			TimeConvert ((ptmp->totaltime / ptmp->totalcount), every);
			count++;
			gip.s_addr = ptmp->groupaddress;
			inet_ntoa_b (gip, ip);
			vty_out (vty, "%-16s%-3d/%-5d%-9s/%-10s%-10s%-9s\r\n", ip,
				ptmp->totalcount, ptmp->previewcount, time, prev, max, every);
			ptmp = ptmp->pNext;
			statcount--;
		}
		return;
	}

	/*显示单个组统计 */
	while (statcount)
	{
		if (ptmp->groupaddress == groupaddress)
		{
			memset (max, 0, 9);
			memset (time, 0, 9);
			memset (every, 0, 9);
			TimeConvert (ptmp->totaltime, time);
			TimeConvert (ptmp->previewtime, prev);
			TimeConvert (ptmp->maxtime, max);
			TimeConvert ((ptmp->totaltime / ptmp->totalcount), every);
			gip.s_addr = ptmp->groupaddress;
			inet_ntoa_b (gip, ip);
			vty_out (vty, "%-16s%-3d/%-6d%-9s/%-10s%-10s%-9s\r\n", ip,
				ptmp->totalcount, ptmp->previewcount, time, prev, max, every);
			ptmp = ptmp->pNext;
			return;
		}
		statcount--;
		ptmp = ptmp->pNext;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -