毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 论文 >> 正文

计算机防火墙论文 第15页

更新时间:2008-4-19:  来源:毕业论文

 

4.3 一些仿真中的代码

 

规则匹配优化算法:

#include "stdafx.h"

#include <afxwin.h>

#include <iostream>

using namespace std;

#define IDT_TIMER 1000

 

struct {

       int rule;

       int Count;

}Rule[100], mun_temp;

 

void main()

{

       CFile file;

       CString strPath, strData, strTime, str;

       strPath = "Rule.txt";

       file.Open(strPath, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeRead);

       int i = file.GetLength();

       file.SeekToBegin();

       int len = file.Read(strData.GetBuffer(12408), 12408);

       strData.ReleaseBuffer();

       int nPos1 = 0;

       int nPos = 0;

       int nLength = 0;

       nLength = strData.GetLength();

       strData = strData.Left(nLength);

       cout <<"规则"<<"\t"<<"匹配次数"<<endl;

       for(i = 0; ; i++)

       {

              nLength = strData.GetLength();

              nPos = strData.Find(" ", 0);

              str = strData.Left(nPos);

              strData = strData.Right(nLength-nPos-1);

              nPos1 = strData.Find("\n", 0);

              strTime = strData.Left(nPos1-1);

              strData = strData.Right(nLength-nPos1-nPos-1);

              if(nPos < 0)

                     break;

              int nstr = atoi(str);

              int nstrTime = atoi(strTime);

              cout << nstr << "\t"<<nstrTime <<endl;

              Rule[i].rule = nstr;

              Rule[i].Count = 0;

       }

       file.Close();

 

       cout << i <<endl;

       cout <<"初始化成功!"<<endl;

       cout <<"规则"<<"\t"<<"匹配次数"<<endl;

       for(int j=0; j <= i-1; j++)

       {

              cout << Rule[j].rule << "\t"<<Rule[j].Count << endl;

       }

       cout <<"请输入数据 输入-1结束"<< endl;

 

       int Data;

       cin >> Data;

       while (Data!=-1) {

              for(j=0; j <= i-1; j++)

              {

                     if (Rule[j].rule == Data) {

                            Rule[j].Count++;

                     }

              }

              cin >> Data;

       }

       cout <<"规则"<<"\t"<<"匹配次数"<<endl;

       for(j=0; j <= i-1; j++)

       {

              cout << Rule[j].rule << "\t"<<Rule[j].Count << endl;

       }

      

       for(int k=0; k<i; k++)

       {

              for(int q=0; q<i; q++)

              {

                     if (Rule[k].Count > Rule[q].Count) {

                            mun_temp = Rule[k];

                            Rule[k] = Rule[q];

                            Rule[q] = mun_temp;

 

                     }

              }

       }

       cout <<"排序后"<< endl;

       cout <<"规则"<<"\t"<<"匹配次数"<<endl;

       for( j=0; j <= i-1; j++)

       {

              cout << Rule[j].rule << "\t"<<Rule[j].Count << endl;

       }

 

       CStdioFile ifile;

       ifile.Open(strPath,CFile::modeCreate|CFile::modeWrite);

       for(j=0; j <= i-1; j++)

       {

              CString strWrite;

              strWrite.Format("%d %d\n", Rule[j].rule, Rule[j].Count);

              ifile.SeekToEnd();

              ifile.WriteString(strWrite);

       }

      

       ifile.Close();

      

}

TCL代码:

 

# 产生一个模拟的对象

set ns [new Simulator]

 

#针对不同的资料流定义不同的颜色,这是要给NAM用的

$ns color 1 Blue

#开启一个NAM trace file

set nf [open out.nam w]

$ns namtrace-all $nf

 

#开启一个trace file用来记录封包传送的过程

set nd [open out0.tr w]

$ns trace-all $nd

 

#定义一个结束的程序

proc finish {} {

        global ns nf nd

        $ns flush-trace

        close $nf 

        close $nd 

 

#以背景执行的方式去执行NAM

           exec nam out.nam &

        exit 0

}

 

#产生七个节点

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

set n6 [$ns node]

 

#把节点连接起来

$ns duplex-link $n0 $n5 10Mb 10ms DropTail

$ns duplex-link $n1 $n5 10Mb 10ms DropTail

$ns duplex-link $n2 $n5 10Mb 10ms DropTail

$ns duplex-link $n3 $n5 10Mb 10ms DropTail

$ns duplex-link $n4 $n5 10Mb 10ms DropTail

$ns duplex-link $n6 $n5 5Mb 20ms DropTail

 

#设定n5n6之间的Queue Size2000个封包大小

$ns queue-limit $n5 $n6 2000

 

#设定节点的位置这是要给NAM用的

$ns duplex-link-op $n0 $n5 orient down

$ns duplex-link-op $n1 $n5 orient right-down

$ns duplex-link-op $n2 $n5 orient right

$ns duplex-link-op $n3 $n5 orient right-up

$ns duplex-link-op $n4 $n5 orient up

$ns duplex-link-op $n5 $n6 orient right

 

#观测n5n6之间queue的变化这是要给NAM用的

$ns duplex-link-op $n5 $n6 queuePos 0.5

 

#n0节点建立一条UDP的连线

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set null0 [new Agent/Null]

$ns attach-agent $n6 $null0

$ns connect $udp0 $null0

#UDP连线之上建立CBR应用程式

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set type_ CBR

$cbr0 set packet_size_ 300

$cbr0 set rate_ 1mb

$cbr0 set random_ false

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set null0 [new Agent/Null]

$ns attach-agent $n6 $null0

$ns connect $udp1 $null0

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set type_ CBR

$cbr1 set packet_size_ 300

$cbr1 set rate_ 1mb

$cbr1 set random_ false

set udp2 [new Agent/UDP]

$ns attach-agent $n2 $udp2

set null0 [new Agent/Null]

$ns attach-agent $n6 $null0

$ns connect $udp2 $null0

set cbr2 [new Application/Traffic/CBR]

 << 上一页  [11] [12] [13] [14] [15] [16] [17] 下一页

计算机防火墙论文 第15页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©751com.cn 辣文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。