资源简介
本程序采用MFC编程实现,模拟实现了RIP,OSPF,BGP这3种路由协议的工作原理,由此来显示各自的优缺点,以此来加强对计算机网络层路由协议算法的理解。
代码片段和文件信息
#include “StdAfx.h“
#include “BGPClientThread.h“
#include “WSocket.h“
#include “ResourceManager.h“
#include “BGPDlg.h“
IMPLEMENT_DYNCREATE(CBGPClientThread CWinThread)
CBGPClientThread::CBGPClientThread(void)
{
m_pSocket = new CWSocket();
}
CBGPClientThread::~CBGPClientThread(void)
{
}
BEGIN_MESSAGE_MAP(CBGPClientThread CWinThread)
ON_THREAD_MESSAGE(WM_START onstart)
ON_THREAD_MESSAGE(WM_RECEIVE_PATH OnReceivePath)
END_MESSAGE_MAP()
// CReaderWorkerThread message handlers
BOOL CBGPClientThread::InitInstance()
{
m_pResourceManagerInstance = CResourceManager::GetInstance();
return TRUE;
}
int CBGPClientThread::ExitInstance()
{
return CWinThread::ExitInstance();
}
void CBGPClientThread::onstart(WPARAM wParam LPARAM lParam)
{
m_pBGPDlg = (CBGPDlg*)wParam;
DispatchRouterTable();
}
void CBGPClientThread::OnReceivePath(WPARAM wParam LPARAM lParam)
{
int nStartNet = (int)wParam;
int nEndNet = (int)lParam;
ReceivePath(nStartNet nEndNet);
}
int CBGPClientThread::DispatchRouterTable()
{
CString strMsg = “01“;
int nNodeNum = m_pResourceManagerInstance->m_vecBGPNodes.size();
strMsg.AppendFormat(“%.2d“nNodeNum);
//for(int i = 0 ; i < nNodeNum; i++)
//{
// strMsg.AppendFormat(“%.4d“m_pResourceManagerInstance->m_vecBGPNodes[i]);
//}
int nEdgeNum = m_pResourceManagerInstance->m_vecBGPEdges.size();
strMsg.AppendFormat(“%.2d“nEdgeNum);
for(int i = 0; i < nEdgeNum; i ++)
{
strMsg.AppendFormat(“%.2d%.2d“
m_pResourceManagerInstance->m_vecBGPEdges[i].first
m_pResourceManagerInstance->m_vecBGPEdges[i].second);
}
for(int i = 7001; i < 7009; i++)
{
m_pSocket->Init();
if(FALSE == m_pSocket->Connect(“127.0.0.1“ i))
{
// LOG 服务器连接失败
return -1;
}
m_pSocket->Write(strMsg strMsg.GetLength());
m_pSocket->Close();
}
return 0;
}
int CBGPClientThread::ReceivePath(int nStartNet int nEndNet)
{
int nStartRouter = m_pResourceManagerInstance->m_mapBGPNetAS[nStartNet];
int nEndRouter = m_pResourceManagerInstance->m_mapBGPNetAS[nEndNet];
m_pSocket->Init();
if(FALSE == m_pSocket->Connect(“127.0.0.1“ nStartRouter + 7000))
{
// LOG 服务器连接失败
return -1;
}
// 消息格式,02目的路由(4byte)
CString strMsg = “02“;
strMsg.AppendFormat(“%.2d“nEndRouter);
m_pSocket->Write(strMsg strMsg.GetLength());
CString str;
m_pSocket->Read(str2);
if(“02“ != str)
{
// LOG 消息解析错误
m_pSocket->Close();
return -2;
}
m_pSocket->Read(str2);
int nStrLength = atoi(str);
CString sPath;
m_pSocket->Read(sPathnStrLength);
std::string szPath = sPath.GetBuffer(0);
std::list* lstRouters = new std::list();
for(int i = 0; i < szPath.size(); i++)
{
char ch = szPath.at(i);
lstRouters->push_back(ch);
if(nStartRouter-1 == ch-‘0‘)
{
break;
}
}
m_pBGPDlg->PostMessage(WM_RECEIVE_PATH (WPARAM)lstRouters NULL);
m_pSocket->Close();
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3007 2014-05-05 21:44 Master\Master\BGPClientThread.cpp
文件 684 2014-05-01 14:59 Master\Master\BGPClientThread.h
文件 6928 2014-05-05 21:45 Master\Master\BGPDlg.cpp
文件 1151 2014-05-05 20:49 Master\Master\BGPDlg.h
文件 5055 2014-05-05 21:40 Master\Master\BGPServerThread.cpp
文件 1359 2014-05-01 16:12 Master\Master\BGPServerThread.h
文件 3575 2014-05-02 23:22 Master\Master\ClassDiagram1.cd
文件 332585 2014-05-05 21:44 Master\Master\Debug\BGPClientThread.obj
文件 171207 2014-05-05 21:45 Master\Master\Debug\BGPDlg.obj
文件 390869 2014-05-05 21:41 Master\Master\Debug\BGPServerThread.obj
文件 12822 2014-05-05 21:45 Master\Master\Debug\cl.command.1.tlog
文件 99072 2014-05-05 21:45 Master\Master\Debug\CL.read.1.tlog
文件 16380 2014-05-05 21:45 Master\Master\Debug\CL.write.1.tlog
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
文件 2 2014-06-12 16:50 Master\Master\Debug\li
............此处省略86个文件信息
- 上一篇:grid+report5.6锐浪报表完美破解
- 下一篇:图像灰度化软件
评论
共有 条评论