TrafficView.cpp
上传用户:hbytqc8
上传日期:2014-07-31
资源大小:527k
文件大小:7k
- // TrafficView.cpp : implementation of the CTrafficView class
- //
- #include "stdafx.h"
- #include "Traffic.h"
- #include "Input.h"
- #include "TrafficDoc.h"
- #include "TrafficView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CTrafficView
- IMPLEMENT_DYNCREATE(CTrafficView, CFormView)
- BEGIN_MESSAGE_MAP(CTrafficView, CFormView)
- //{{AFX_MSG_MAP(CTrafficView)
- ON_COMMAND(ID_SCAN, OnScan)
- ON_COMMAND(ID_START, OnStart)
- ON_WM_TIMER()
- ON_COMMAND(ID_END, OnEnd)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTrafficView construction/destruction
- CTrafficView::CTrafficView()
- : CFormView(CTrafficView::IDD)
- {
- //{{AFX_DATA_INIT(CTrafficView)
- //}}AFX_DATA_INIT
- // TODO: add construction code here
- ip="127.0.0.1";
- community="public";
- oid="1.3.6.1.2.1.2.2.1";
- last_in=0;
- last_out=0;
- last_time=0;
- }
- CTrafficView::~CTrafficView()
- {
- }
- void CTrafficView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CTrafficView)
- DDX_Control(pDX, IDC_LIST1, m_list1);
- //}}AFX_DATA_MAP
- }
- BOOL CTrafficView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CFormView::PreCreateWindow(cs);
- }
- void CTrafficView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
- GetParentFrame()->RecalcLayout();
- ResizeParentToFit();
- m_list1.InsertColumn(0," 类型 ",LVCFMT_LEFT,80,0);
- m_list1.InsertColumn(1," 名称(DLCI)",LVCFMT_LEFT,130,1);
- m_list1.InsertColumn(2," 状态 ",LVCFMT_LEFT,70,2);
- m_list1.InsertColumn(3," 辅助信息 ",LVCFMT_LEFT,300,3);
- m_list1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CTrafficView printing
- BOOL CTrafficView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CTrafficView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CTrafficView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- void CTrafficView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
- {
- // TODO: add customized printing code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CTrafficView diagnostics
- #ifdef _DEBUG
- void CTrafficView::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CTrafficView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- CTrafficDoc* CTrafficView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTrafficDoc)));
- return (CTrafficDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CTrafficView message handlers
- void CTrafficView::OnScan()
- {
- CString BaseOid;
- CInput dlg;
- if (dlg.DoModal()==IDOK)
- {
- ip=dlg.ip;
- community=dlg.m_community;
- }
- m_snmp.clear();
- BaseOid="1.3.6.1.2.1.2.2.1.1";
- m_snmp.GetTree(ip,community,BaseOid);
- BaseOid="1.3.6.1.2.1.2.2.1.2";
- m_snmp.GetTree(ip,community,BaseOid);
- BaseOid="1.3.6.1.2.1.2.2.1.8";
- m_snmp.GetTree(ip,community,BaseOid);
- int row=m_snmp.GetCount()/3;
- for (int i=0;i<row;i++)
- {
- pLine=new Line;
- pLine->Type="普通接口";
- pLine->Index=m_snmp.GetValue(i);
- pLine->Name=m_snmp.GetValue(i+row);
- if (m_snmp.GetValue(i+2*row)=="1")
- pLine->State="UP";
- else
- pLine->State="Down";
- pLine->Descr="";
- pLine->Ip=ip;
- LineArray.Add(pLine);
- }
- m_snmp.clear();
- BaseOid="1.3.6.1.2.1.4.20.1.2";
- m_snmp.GetTree(ip,community,BaseOid);
- CString temp;
- for (i=0;i<m_snmp.GetCount();i++)
- {
- for (int j=0;j<LineArray.GetSize();j++)
- if (m_snmp.GetValue(i)==LineArray[j]->Index)
- {
- temp=m_snmp.GetOid(j);
- temp=temp.Right(temp.GetLength()-21);
- LineArray[j]->Descr="IP:"+temp;
- break;
- }
-
- }
- for (int j=0;j<LineArray.GetSize();j++)
- {
- BaseOid="1.3.6.1.2.1.31.1.1.1.18."+LineArray[j]->Index;
- m_snmp.GetOne(ip,community,BaseOid,temp);
- LineArray[j]->Descr+=" 备注:"+temp;
- }
- //获取网络接口的信息并保存;
- m_snmp.clear();
- BaseOid="1.3.6.1.2.1.10.32.2.1.1";
- m_snmp.GetTree(ip,community,BaseOid);
- BaseOid="1.3.6.1.2.1.10.32.2.1.2";
- m_snmp.GetTree(ip,community,BaseOid);
- BaseOid="1.3.6.1.2.1.10.32.2.1.3";
- m_snmp.GetTree(ip,community,BaseOid);
- row=m_snmp.GetCount()/3;
- for (i=0;i<row;i++)
- {
- pLine=new Line;
-
- pLine->Type="帧中继PVC";
- pLine->Ip=ip;
- pLine->Index=m_snmp.GetValue(i);
- pLine->Name=m_snmp.GetValue(i+row);
- if (m_snmp.GetValue(i+2*row)=="2")
- pLine->State="UP";
- else pLine->State="Down";
- BaseOid="1.3.6.1.4.1.9.9.49.1.2.2.1.2."+pLine->Index+"."+pLine->Name;
- m_snmp.GetOne(ip,community,BaseOid,temp);
- if ("2"==temp)
- {
- CString rv;
- BaseOid="1.3.6.1.4.1.9.9.49.1.2.2.1.3."+pLine->Index+"."+pLine->Name;
- m_snmp.GetOne(ip,community,BaseOid,rv);
- BaseOid="1.3.6.1.2.1.31.1.1.1.18."+rv;
- m_snmp.GetOne(ip,community,BaseOid,rv);
- pLine->Descr=rv;
- }
- else
- {
- CString rv;
- BaseOid="1.3.6.1.4.1.9.9.49.1.3.1.1.3."+pLine->Index+"."+pLine->Name;
- m_snmp.GetOne(ip,community,BaseOid,rv);
- pLine->Descr=rv;
- }
- LineArray.Add(pLine);
-
- }
- m_list1.DeleteAllItems();
- for (i=0;i<LineArray.GetSize();i++)
- {
- m_list1.InsertItem(i,LineArray[i]->Type);
- m_list1.SetItemText(i,1,LineArray[i]->Name);
- m_list1.SetItemText(i,2,LineArray[i]->State);
- m_list1.SetItemText(i,3,LineArray[i]->Descr);
- }
- }
- void CTrafficView::OnStart()
- {
- SetTimer(1,60000,NULL);
- m_snmp.GetThree(ip,community,oid,index,last_in,last_out,last_time);
- }
- void CTrafficView::OnTimer(UINT nIDEvent)
- {
- unsigned long InBits,OutBits;
- unsigned long in_v,out_v,time_v,in_diff,out_diff,time_diff;
- CTime t=CTime::GetCurrentTime();
- CString time=t.Format("%H:%M");
- m_snmp.GetThree(ip,community,oid,index,in_v,out_v,time_v);
- in_diff=in_v-last_in;
- if (in_diff<0)
- in_diff+=4294967295;
- out_diff=out_v-last_out;
- if (out_diff<0)
- out_diff+=4294967295;
- time_diff=time_v-last_time;
- if (time_diff<0)
- time_diff+=4294967295;
- InBits=(in_diff*8)/(time_diff/100);
- OutBits=(out_diff*8)/(time_diff/100);
- last_in=in_v;
- last_out=out_v;
- last_time=time_v;
- //write to a txt file
- /*CString s;
- s.Format("%d",v1);
- MessageBox(s);
- s.Format("%d",v3);
- MessageBox(s);*/
-
- CFormView::OnTimer(nIDEvent);
- }
- void CTrafficView::OnEnd()
- {
- KillTimer(1);
- }