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

📄 igmpcon_cli.c

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

/************************************************************
  Copyright (C), 1999-2006, Fiberhome Tech. Co., Ltd.
  FileName: Igmpcon_cli.c
  Author:  aibin      Version : 1.0          Date: 20061113
  Description:      可控组播命令行模块      
  Version:           1.0
  History:         // 历史修改记录
      <author>  <time>   <version >   <desc>
      Aibin    2006/11/13     1.0     build this moudle  
***********************************************************/

/*#include <cli.h>*/
#include "igmpcon.h"
#include <sys/times.h>

int delay = 0;

/*aibin add for auto upftp igmplog 20080610*/
int auto_upload_igmplog_flag = 0;
int auto_upload_period = 1440;
char auto_upload_igmplog_ftpip[21] = { 0x00 };
char auto_upload_igmplog_ftpuser[21] = { 0x00 };
char auto_upload_igmplog_ftppass[21] = { 0x00 };
int auto_upload_taskid = 0;

/*************************************************
  Function:  ShowOneGroup     
  Description:  show onu online group by pointer 
  Input:    GroupInfo * gtmp, struct vty *vty     	 
  Output:  n/a       
  Return:  n/a       
  Others:        
*************************************************/

void ShowOneGroup (GroupInfo * gtmp, struct vty *vty)
{
	int count, i, j, k;
	struct in_addr gip;
	char ip[20];
	char aa = ',';
	int linecount;
	char portlist[20];
	groupMember *pMember;
	char newslot;

	memset (portlist, 0, sizeof (portlist));
	count = 0;
	gip.s_addr = gtmp->groupaddress;
	inet_ntoa_b (gip, ip);
	vty_out (vty, "Group Address: %s\r\n", ip);
	vty_out (vty, "Current ports(slot:onu:onuPort):\r\n");

	pMember = gtmp->member;
	while (pMember)
	{
		count++;
		if (pMember->slot > 8)
		{
			newslot = pMember->slot + 2;
		}
		else
		{
			newslot = pMember->slot;
		}

		if (pMember->state == MEMBER_NORMAL)
		{
			vty_out (vty, "%2d:%2d:%d%-4c", newslot, pMember->onu,
				pMember->onuPort, aa);
		}
		else
		{
			vty_out (vty, "%2d:%2d:%dp,", newslot, pMember->onu,
				pMember->onuPort, aa);
		}
		pMember = pMember->pNext;
	}
	vty_out (vty, "\n\rTotal ports: %d\r\n", count);
}

/*************************************************
  Function:   ShowGroupBd    
  Description: show group bandwidth by address  
  Input:    UINT groupaddress, struct vty *vty     	 
  Output:   none      
  Return:   none      
  Others:   is groupaddress=0, show all groups bandwidth, otherwise, show single group's    
*************************************************/
void ShowGroupBd (UINT groupaddress, struct vty *vty)
{
	GroupAuth *ptmp;
	GroupInfo *curg;
	int i, j;
	struct in_addr gip;
	char ip[20];

	if (groupaddress)
	{
		ptmp = (GroupAuth *) GetAuthGroup (groupaddress);
		if (NULL == ptmp)
		{
			vty_out (vty, "Not found such group\r\n");
			return;
		}
		else
		{
			gip.s_addr = groupaddress;
			inet_ntoa_b (gip, ip);
			vty_out (vty, "%s  :     %d\r\n", ip, ptmp->bandwidth);
			return;
		}
	}

	i = 0;
	vty_out (vty, "Group                 :     Bandwidth(Kbps)\r\n");
	ptmp = authlist;
	while (ptmp)
	{
		if (ptmp->bandwidth)
		{
			i++;
			gip.s_addr = ptmp->groupaddress;
			inet_ntoa_b (gip, ip);
			curg = (GroupInfo *) GetCurGroup (ptmp->groupaddress);
			if (curg)
			{
				vty_out (vty, "%d.%-20s  :     %d          online\r\n", i, ip,
					ptmp->bandwidth);
			}
			else
			{
				vty_out (vty, "%d.%-20s  :     %d          offline\r\n", i, ip,
					ptmp->bandwidth);
			}
		}
		ptmp = ptmp->pNext;
	}
	vty_out (vty, "Total Current Bandwidth:     %d/%d\r\n", CurrentUpBandwidth,
		MaxUpBandwidth);
	return;
}

/*得到组地址段形式的字符串*/

/*************************************************
  Function:  GetGroupString     
  Description:  convert a group address table to a address string
                     like "a.b.c.d-a.b.c.e,a.b.c.f"
  Input:  char *str, UINT *group, int bufferlen       	 
  Output:         
  Return: success 0, error-1;        
  Others:        
*************************************************/
int GetGroupString (char *str, UINT * group, int bufferlen)
{
	int i, first, last, len;
	UINT add[300];
	UINT temp[100];
	char *p;
	struct in_addr gip1, gip2;
	char ip[20];
	char ip2[20];

	len = 0;
	memset (add, 0, sizeof (add));
	memset (temp, 0, sizeof (temp));

	for (i = 0; i < 256 && group[i]; i++)
	{
		InsertNodebySeq (256, group[i], add);
	}

	i = 0;
	p = str;
	while (add[i] && i < 300)
	{
		first = add[i];
		for (; (add[i + 1] - add[i] == 1); i++);
		last = add[i];
		gip1.s_addr = first;
		gip2.s_addr = last;
		if (first == last)
		{
			inet_ntoa_b (gip1, ip);
			sprintf ((char *) temp, "%s\r\n", ip);
		}
		else
		{
			inet_ntoa_b (gip1, ip);
			inet_ntoa_b (gip2, ip2);
			sprintf ((char *) temp, "%s-%s\r\n", ip, ip2);
		}
		len = len + strlen ((char *) temp);
		if (len > bufferlen)
			return ERROR;
		strcat ((char *) str, (char *) temp);
		memset (temp, 0, sizeof (temp));
		i++;
	}
	return OK;
}

/*配置预览参数*/

/*************************************************
  Function:  SetIgmpPreview     
  Description:  set igmp preview parameters
  Input:  UCHAR count, UCHAR pretime, UCHAR interval, UCHAR resettime,
	UCHAR totaltime, UINT groupaddress       	 
  Output:         
  Return: success 0, error -1       
  Others: if groupaddress = 0, set the preview default parameters, otherwise, set a specifice group;s       
*************************************************/
int SetIgmpPreview (UCHAR count, UCHAR pretime, UCHAR interval, UCHAR resettime,
	UCHAR totaltime, UINT groupaddress)
{
	GroupAuth *ptmp;
	int find = 0;
	int i, j, k;

	/*配置缺省设置 */
	if (groupaddress == 0)
	{
		previewcount = count;
		previewtime = pretime;
		previewinterval = interval;
		previewresettime = resettime;
		previewTotalTime = totaltime;
		return OK;
	}

	/*对具体模版进行配置 */
	ptmp = authlist;
	while (ptmp)
	{
		if (ptmp->groupaddress == groupaddress)
		{
			find = 1;
			ptmp->preCount = count;
			ptmp->preTime = pretime;
			ptmp->preInterval = interval;
			ptmp->preReset = resettime;
			ptmp->pretotaltime = totaltime;
			return OK;
		}
		ptmp = ptmp->pNext;
	}
	if (!find)
	{
		printf ("\r\nAdd this group to profile first!\r\n");
		return -1;
	}
}

/*************************************************
  Function:  ShowGroupInfo     
  Description: 显示当前组的信息  
  Input: UINT groupaddress, struct vty *vty        	 
  Output:         
  Return:         
  Others:  if groupaddress = 0, show all onlines group informations, otherwise, show a specifice group's       
*************************************************/
void ShowGroupInfo (UINT groupaddress, struct vty *vty)
{
	GroupInfo *ptmp;
	int count;
	int find;
	int sem;

	sem = semTake (semConinfo, 1);
	if (ERROR == sem)
	{
		printf ("\r\nSystem is busy! try again later\r\n");
		semtakeerror++;
		return;
	}

	ptmp = infolist;
	count = 0;
	find = 0;

	/*查找单个组信息 */
	if (groupaddress)
	{

		while (ptmp)
		{
			if (ptmp->groupaddress == groupaddress)
			{
				find = 1;
				vty_out (vty, "***************Group Info***************\r\n");
				ShowOneGroup (ptmp, vty);
				vty_out (vty, "******************E N D*****************\r\n");
				sem = semGive (semConinfo);
				if (ERROR == sem)
				{
					printf ("\r\ngive semConinfo error!ShowGroupInfo\r\n");
					semtakeerror++;
				}
				return;
			}
			ptmp = ptmp->pNext;

		}
		if (!find)
		{
			vty_out (vty, "No such Group exist!\r\n");
			vty_out (vty, "******************E N D****************\r\n");
		}
		sem = semGive (semConinfo);
		if (ERROR == sem)
		{
			printf ("\r\ngive semConinfo error!ShowGroupInfo\r\n");
			semtakeerror++;
		}
		return;
	}

	/*查看所有的组信息 */
	while (ptmp)
	{
		count++;
		vty_out (vty, "***************Group NO. %d***************\r\n", count);
		ShowOneGroup (ptmp, vty);
		ptmp = ptmp->pNext;
	}
	if (infolist)
	{
		vty_out (vty, "******************E N D******************\r\n");
	}
	sem = semGive (semConinfo);
	if (ERROR == sem)
	{
		printf ("\r\ngive semConinfo error!ShowGroupInfo\r\n");
		semtakeerror++;
	}
	return;
}

/*************************************************
  Function:   ShowOneAuth    
  Description:  show one auth group by pointer 
  Input: GroupAuth * gtmp, struct vty *vty        	 
  Output:         
  Return:         
  Others:        
*************************************************/
void ShowOneAuth (GroupAuth * gtmp, struct vty *vty)
{
	int count, slot, onu, port;
	int state;
	struct in_addr gip;
	char ip[20];
	int linecount;
	char aa = ',';
	char tmpno;
	char newslot;

	count = 0;
	gip.s_addr = gtmp->groupaddress;
	inet_ntoa_b (gip, ip);
	vty_out (vty, "Group Address    : %s\r\n", ip);
	vty_out (vty, "Preview times    : %d\r\n", gtmp->preCount);
	vty_out (vty, "Preview duration : %d(min)\r\n", gtmp->preTime);
	vty_out (vty, "Preview interval : %d(min)\r\n", gtmp->preInterval);
	vty_out (vty, "preview reset    : %d(hr)\r\n", gtmp->preReset);
	vty_out (vty, "preview total    : %d(min)\r\n", gtmp->pretotaltime);
	vty_out (vty, "Leave delay      : %d(sec)\r\n", gtmp->leavedelay);
	if (gtmp->vlanid)
		vty_out (vty, "VLAN ID          : %d\r\n", gtmp->vlanid);
	else
		vty_out (vty, "VLAN ID          : %d\r\n", global_vlan);
	if (!gtmp->bandwidth)
		vty_out (vty, "Bandwidth        : Not setted\r\n");
	else
		vty_out (vty, "Bandwidth        : %d(Kbps)\r\n", gtmp->bandwidth);
	vty_out (vty, "Authorized ports :");
	for (slot = 1; slot <= MAX_DOWN_SLOT; slot++)
	{
		linecount = 0;
		for (onu = 1; onu <= MaxOnu; onu++)
		{
			for (port = 1; port <= MaxOnuPort; port++)
			{
				tmpno = portstatlist[slot][onu][port].tmpno;
				if (tmpno == 0)
				{
					continue;
				}

				if (gtmp->profile[tmpno])
				{
					linecount++;
					count++;
					if (linecount % 8 == 1)
					{
						vty_out (vty, "\r\n");
					}

					if (gtmp->profile[tmpno] == MEMBER_NORMAL)
					{
						if (slot <= 8)
							vty_out (vty, "%2d:%2d:%2d%-4c", slot, onu, port,
								aa);
						else
							vty_out (vty, "%2d:%2d:%2d%-4c", slot + 2, onu,
								port, aa);
					}
					else
					{
						if (slot <= 8)
							vty_out (vty, "%2d:%2d:%2d(p),", slot, onu, port);
						else
							vty_out (vty, "%2d:%2d:%2d(p),", slot + 2, onu,
								port);
					}
				}
			}
		}
	}
	vty_out (vty, "\r\nTotal ports: %d\r\n", count);
}

/*显示组配置信息*/

/*************************************************
  Function: ShowAuthGroup      
  Description:  show auth group information
  Input:   INT groupaddress, struct vty *vty      	 
  Output:         
  Return:         
  Others:  if groupaddress =0, show all auth groups, otherwise show group by address      
*************************************************/
void ShowAuthGroup (UINT groupaddress, struct vty *vty)
{
	GroupAuth *ptmp;
	int count;
	int find = 0;

	ptmp = authlist;
	count = 0;

	/*查找单个组信息 */
	if (groupaddress)
	{
		while (ptmp)
		{
			if (ptmp->groupaddress == groupaddress)
			{
				find = 1;
				vty_out (vty,
					"***************Auth Group Info***************\r\n");
				ShowOneAuth (ptmp, vty);
				vty_out (vty,
					"********************E N D*******************\r\n");
				return;
			}
			ptmp = ptmp->pNext;

		}
		if (!find)
		{
			vty_out (vty, "No such Group exist!\r\n");
			vty_out (vty, "********************E N D*******************\r\n");
		}
		return;
	}

	/*查看所有的组信息 */
	while (ptmp)
	{
		count++;
		vty_out (vty, "***************Auth Group NO. %d***************\r\n",
			count);
		ShowOneAuth (ptmp, vty);
		ptmp = ptmp->pNext;
	}
	if (authlist)
	{
		vty_out (vty, "**********************E N D*******************\r\n");
	}
	return;
}

/*显示日志记录*/

/*************************************************
  Function:  ShowGroupRecord     
  Description: show igmp record   
  Input:  USHORT count, struct vty *vty       	 
  Output:         
  Return:         
  Others: the list number of logs is determined by count       
*************************************************/
void ShowGroupRecord (USHORT count, struct vty *vty)
{
	PortRecord *ptmp;
	struct in_addr gip;
	char ip[20];
	int i = 0, j = 0;
	int slotnew;
	int pvc;
	int semlog;

	/*显示全部 */
	if (!count)
	{
		count = recordcount;
	}

	if (count >= recordcount)
	{
		count = recordcount;
	}

	semlog = semTake (semConLog, 1);
	if (ERROR == semlog)
	{
		printf ("Take semConLog error!\r\n");
		semtakeerror++;
		return;
	}
	ptmp = recordlist;
	j = 0;
	while (ptmp && count)
	{
		gip.s_addr = ptmp->groupaddress;
		inet_ntoa_b (gip, ip);
		slotnew = ptmp->slot;
		if (slotnew > 8)
		{
			slotnew = slotnew + 2;
		}
		j++;

		/*加入 */
		if (ptmp->cmd == 1)
		{
			if (ptmp->preview == 2)
			{
				if (ptmp->state == success)
				{
					vty_out (vty,
						"%d.%s, port(%2d:%2d:%1d)(p) joins  group(%s) successfully.\n",
						j, ptmp->time, slotnew, ptmp->onu, ptmp->onuPort, ip);
				}
				else if (ptmp->state == failpreview)
				{
					vty_out (vty,
						"%d.%s, port(%2d:%2d:%1d)(p) fails to join  group(%s): not has preview right this moment.\n",
						j, ptmp->time, slotnew, ptmp->onu, ptmp->onuPort, ip);

⌨️ 快捷键说明

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