if (PACKET_TEST_ACTION(p, ACTION_REJECT)) { r = RejectSendLibnet11L3IPv4TCP(tv, p, data, REJECT_DIR_SRC); SCReturnInt(r); } else if (PACKET_TEST_ACTION(p, ACTION_REJECT_DST)) { r = RejectSendLibnet11L3IPv4TCP(tv, p, data, REJECT_DIR_DST); SCReturnInt(r); } else if(PACKET_TEST_ACTION(p, ACTION_REJECT_BOTH)) {
时间: 2024-03-29 09:38:46 浏览: 50
这段代码看起来像是一个网络安全相关的程序,它检测了包(packet)中是否包含了拒绝(reject)的动作(action),如果包含了,就会调用RejectSendLibnet11L3IPv4TCP函数,传入tv、p、data和REJECT_DIR_SRC或REJECT_DIR_DST参数(具体传入哪个参数取决于ACTION_REJECT和ACTION_REJECT_DST的值)。最后,它还检测了是否同时包含了ACTION_REJECT和ACTION_REJECT_DST,如果是的话,也会调用RejectSendLibnet11L3IPv4TCP函数,传入tv、p、data和REJECT_DIR_BOTH参数。
相关问题
module data_packetizer ( input clk, input rst, input [15:0] data_in, output reg tx_wire, output reg ready ); reg [1:0] state = 2'b00; reg [35:0] packet_out; reg parity; always @(posedge clk) begin if (rst) begin state <= 2'b00; ready <= 0; packet_out <= 36'h000000; end else begin case(state) 2'b00: begin ready <= 0; if (data_in != 0) begin state <= 2'b01; end end 2'b01: begin packet_out[32:17] <= data_in; state <= 2'b10; end 2'b10: begin if (data_in != 0) begin state <= 2'b11; end end 2'b11: begin packet_out[16:1] <= data_in; packet_out[35:33] <= 3'b101; packet_out[0] <= ^packet_out[34:3]; ready <= 1; state <= 2'b00; end endcase end end reg tx_state; reg tx_stop; always @(posedge clk) begin if (rst) tx_state<=0; else if(tx_stop) tx_state<=0; else if(ready) tx_state<=1; else tx_state<=tx_state; end reg [6:0]cnt; always @(posedge clk) begin if (rst)begin tx_wire<=1'b1; tx_stop<=1'b0; cnt<='d35; end else if(tx_state)begin if(cnt==0)begin tx_wire<=packet_out[cnt]; tx_stop<=1'b1; cnt<='d35; end else begin cnt<=cnt-1'b1; tx_stop<=1'b0; tx_wire<=packet_out[cnt]; end end else begin tx_wire<=1'b1; tx_stop<=1'b0; cnt<='d35; end end endmodule
这是一个 Verilog HDL 实现的数据封装器模块,用于将输入的数据以特定格式打包成数据包,以便于在通信中传输。常用于串口通信等场景。
该模块有以下输入和输出:
- 输入:时钟信号 clk、复位信号 rst、16 位数据信号 data_in。
- 输出:数据包信号 tx_wire、数据包就绪信号 ready。
该模块采用状态机实现,具有四个状态:
- 状态 00:空闲状态,等待非零数据输入。
- 状态 01:输入高 16 位数据。
- 状态 10:等待低 16 位数据输入。
- 状态 11:计算校验位并将数据包标记为就绪。
该模块还包含一个计数器 cnt,用于控制数据包中每一位数据的输出。当数据包就绪时,计数器开始计数并将数据包中的数据逐位输出到 tx_wire 信号,直到输出完毕。
在输出数据包时,还需要设置 tx_stop 信号,以便接收端能够判断数据包的末尾位置。
WORD32 packetShadowDelete(SDDM_LPP_PACKET_KEY* pPacketKey, SDDM_LPP_PACKET* pPacketValue) { WORD32 dwRet = ROSNG_PARAM_ERROR; WORD32 so_desc = 0; WORD32 tcp_index = 0; if((NULL == pPacketKey) || (NULL == pPacketValue)) { ROSNG_TRACE_WARNING("Invalid para!!!\n"); goto error; } so_desc = pPacketValue->so_desc; tcp_index = pPacketValue->sddm_tcp_packet_cb.index; if((TCP_RECV_QUEUE == pPacketValue->pkt_queue) && (0 != so_desc)) { if(ROSNG_SUCCESS != packetShadowDeletePkt(&gSocketTable.packetRecvAvlTree,pPacketKey,pPacketValue,so_desc)) { ROSNG_TRACE_WARNING("packetShadowDeletePkt fail\n"); goto error; } } else if((TCP_SEND_QUEUE == pPacketValue->pkt_queue) && (0 != tcp_index)) { if(ROSNG_SUCCESS != packetShadowDeletePkt(&tcp_config.packetSendAvlTree,pPacketKey,pPacketValue,tcp_index)) { ROSNG_TRACE_WARNING("packetShadowDeletePkt fail\n"); goto error; } } else { XOS_ASSERT(0); goto error; } dwRet = ROSNG_SUCCESS; error: return dwRet; } 用c语言写一个ft测试用例
以下是一个简单的ft测试用例,测试packetShadowDelete函数是否能够正常处理输入参数并返回正确的结果。
```c
#include <stdio.h>
#include <assert.h>
typedef unsigned int WORD32;
typedef struct {
WORD32 index;
} SDDM_TCP_PACKET_CB;
typedef struct {
WORD32 so_desc;
SDDM_TCP_PACKET_CB sddm_tcp_packet_cb;
WORD32 pkt_queue;
} SDDM_LPP_PACKET;
typedef struct {
// some fields
} SDDM_LPP_PACKET_KEY;
#define TCP_RECV_QUEUE 0
#define TCP_SEND_QUEUE 1
#define ROSNG_SUCCESS 0
#define ROSNG_PARAM_ERROR -1
#define ROSNG_TRACE_WARNING(...) printf(__VA_ARGS__)
#define XOS_ASSERT(...) assert(__VA_ARGS__)
typedef struct {
// some fields
} PacketAvlTree;
PacketAvlTree packetRecvAvlTree;
PacketAvlTree packetSendAvlTree;
WORD32 packetShadowDeletePkt(PacketAvlTree* tree, SDDM_LPP_PACKET_KEY* key, SDDM_LPP_PACKET* value, WORD32 index) {
// some implementation
return ROSNG_SUCCESS;
}
WORD32 packetShadowDelete(SDDM_LPP_PACKET_KEY* pPacketKey, SDDM_LPP_PACKET* pPacketValue) {
WORD32 dwRet = ROSNG_PARAM_ERROR;
WORD32 so_desc = 0;
WORD32 tcp_index = 0;
if((NULL == pPacketKey) || (NULL == pPacketValue))
{
ROSNG_TRACE_WARNING("Invalid para!!!\n");
goto error;
}
so_desc = pPacketValue->so_desc;
tcp_index = pPacketValue->sddm_tcp_packet_cb.index;
if((TCP_RECV_QUEUE == pPacketValue->pkt_queue) && (0 != so_desc))
{
if(ROSNG_SUCCESS != packetShadowDeletePkt(&packetRecvAvlTree,pPacketKey,pPacketValue,so_desc))
{
ROSNG_TRACE_WARNING("packetShadowDeletePkt fail\n");
goto error;
}
}
else if((TCP_SEND_QUEUE == pPacketValue->pkt_queue) && (0 != tcp_index))
{
if(ROSNG_SUCCESS != packetShadowDeletePkt(&packetSendAvlTree,pPacketKey,pPacketValue,tcp_index))
{
ROSNG_TRACE_WARNING("packetShadowDeletePkt fail\n");
goto error;
}
}
else
{
XOS_ASSERT(0);
goto error;
}
dwRet = ROSNG_SUCCESS;
error:
return dwRet;
}
int main() {
SDDM_LPP_PACKET_KEY key;
key.some_field = 123;
SDDM_LPP_PACKET value;
value.so_desc = 456;
value.sddm_tcp_packet_cb.index = 789;
value.pkt_queue = TCP_RECV_QUEUE;
WORD32 ret = packetShadowDelete(&key, &value);
assert(ret == ROSNG_SUCCESS);
return 0;
}
```
阅读全文