📄 count_dl.c
字号:
// Copyright (C) 2002-2003 Intel Corporation, All Rights Reserved.
// Permission is hereby granted to merge this program code with
// other program material to create a derivative work. This
// derivative work may be distributed in compiled object form only.
// Any other publication of this program, in any form, without the
// explicit permission of the copyright holder is prohibited.
//
// Send questions and comments to erik.j.johnson@intel.com,
// aaron.kunze@intel.com
//-------------------------------------------------------------------
// count_dl.c - Chapter 5
// This file contains a dispatch loop which dequeues packets from
// receive, counts them, and enqueues them
// for transmit using a single thread
//
// Include Files
#include "dl_system.h"
#include "system_init.h"
#include "dispatch_loop.h"
#include "dl_source.h"
#include "count.h"
#include "dl_buf.c"
#include "dl_meta.h"
#include "ethernet.h"
#include "ethernet_internal.h"
#include "tos.h"
//#include "ipv4_five_tuple_class_internal.h"
//-----------------------------------------------------------
// Global variables/Registers
//-----------------------------------------------------------
dl_buf_handle_t dlBufHandle;
__declspec(gp_reg) int dlNextBlock;
extern dl_meta_t dlMeta;
void main()
{
unsigned int eth_proto = 0;
//-------------------------------------------------------
// Initialize the blocks
//-------------------------------------------------------
// Initialize the system
system_init();
// Initialize the outgoing ring
dl_sink_init();
// counter and tos initialization
ethernet_init();
tos_init();
// Initialize the incoming ring
dl_source_init();
//-------------------------------------------------------
// dispatch loop
//----------------_--------------------------------------
while(1)
{
// Dequeue a packet from the rx task
dl_source();
if (dlBufHandle.value == 0)
{
continue;
}
// Increment the counters
//count();
// Verify that this packet is an acceptable
// Ethernet packet and that it is locally
// addressed.
ethernet_validate();
if (dlNextBlock != ETHERNET_VALIDATE_LOCAL)
{
goto drop;
}
// At this point we know we have an Ethernet II
// packet. Before we send it to the IPv4
// classifier, we have to make sure that it is
// an IP packet. Then, since the classifier is
// L2 agnostic, we have to move the packet data
// pointer past the Ethernet header.
ethernet_strip_header();
if (dlNextBlock != ETHERNET_PROTO_IP)
{
goto drop;
}
eth_proto = dlNextBlock;
// Now that we have a packet, send it the IPv4
// 5-tuple classifier. The classifier will
// assign an output ring, and a next hop IP
// address.
tos();
//if (dlNextBlock == IX_DROP)
//{
//goto drop;
//}
// Before we transmit the packet, we have to add
// the Ethernet header back on. We do this
// based on the next hop IP address retrieved
// from the classifier.
ethernet_add_header(eth_proto);
if (dlNextBlock == IX_DROP)
{
goto drop;
}
// Now that the output ring is assigned, send it
// to the RED buffer manager to either enqueue
// or drop
//red();
//if (dlNextBlock == IX_DROP)
//{
//goto drop;
//}
// Once we get here, the packet is put on the
// ring to go to transmit.
dl_sink();
continue;
drop:
Dl_BufDrop(dlBufHandle);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -