解决办法的核心是通过NetFPGA的上位机获取NetFPGA中的对于寄存器组中单个或者多个数据包统计寄存器的统计数据,通过计算,得到当前网络流量统计数据,在上位机直接显示,或者通过上位机的网络接口,将数据传送到流量监测平台;
实现当前网络数据流量的远程实时监控,可以为调整NetFPGA上的硬件系统配置和上位机的相应软件系统去适应复杂网络环境的判定提供直接的依据。
下面是对 TX_QUEUE_1_NUM_PKTS_SENT_REG 寄存器信息的获取与传输
具体实现的关键代码如下所示:
clearStatsButton.setText("Send");
clearStatsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Runnable run = new Runnable()
clearStatsButton.setText("Stop");
System.out.println("Statistic Thread Running......");
ServerSocket ss = new ServerSocket(5000);
//Socket client = new Socket("192.168.0.130",5000);
Socket socket = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
OutputStream os = socket.getOutputStream();
DataOutputStream ou = new DataOutputStream(os);
for(int t = 1; t <= 50; t )
i = nf2.readReg(NFDeviceConsts.TX_QUEUE_1_NUM_PKTS_SENT_REG);
Thread.currentThread().sleep(1000);
j = nf2.readReg(NFDeviceConsts.TX_QUEUE_1_NUM_PKTS_SENT_REG);
System.out.printf("%d Packets Sended\n",j-i);
System.out.println("Send OK");
Thread.currentThread().sleep(100);
Thread t = new Thread(run);
}