Hello,
I’m having problems with sending custom packets using the 
ofproto_dpif_send_packet().
As said in the previoius thread 
https://mail.openvswitch.org/pipermail/ovs-discuss/2020-June/050204.html I 
thought to have correctly created a custom udp packet that contains as a 
payload a buffer of dp_packets this is the code:


struct my_captured_packet
{
    struct dp_packet packet;
    int sizeofpayload;
};
static struct my_captured_packet dp_packet_buff1[PACKET_BUFF_ELEMENTS];

//function to copy incoming packets to dp_packet_buff1
//…..

//function part to send the buffer of packets as payload of new udp packet
struct dp_packet *packetAggr;
packetAggr = dp_packet_new(65535);

struct flow flow;
//extract a flow from a buffed pkt
flow_extract(&dp_packet_buff1[0].packet, &flow);
//use the flow to build a new packet
flow_compose(packetAggr, &flow, NULL, 0);

//copy buffer as udp payload
memcpy((char *) dp_packet_l4(packetAggr) + UDP_HEADER_LEN, dp_packet_buff1, 
sizeof(dp_packet_buff1));


//Then I reversed the procedure to see if I could extract the single packets 
from the payload of my custom packet
//struct my_captured_packet *recvdpackets = (struct my_captured_packet *) 
dp_packet_get_udp_payload(packetAggr);
//print dp_packet payloads extracted

for(int j=0; j<PACKET_BUFF_ELEMENTS; j++)
{
            VLOG_ERR("payload #%d: %.*s with size of packet %d", j, 
recvdpackets[j].sizeofpayload, (char *) 
dp_packet_get_udp_payload(&recvdpackets[j].packet),
           (int) dp_packet_size(&recvdpackets[j].packet) );

}

const struct ofproto_dpif *ofproto = ctx->xin->ofproto;
const struct ofport_dpif *portAggr;
ofp_port_t out_port = 2;
portAggr = ofp_port_to_ofport(ofproto, out_port);


ofproto_dpif_send_packet(portAggr, false,  packetAggr);


The above code works as intended, meaning after creating packetAggr and setting 
its payload to dp_packet_buff1 I can cast it back to its original type after 
retrieving it with dp_packet_get_udp_payload, and print the single packets.
However after I send this packet and do this same exact procedure as part of a 
new action that is intended to just extract the payload and single packets, the 
cast to struct my_captured_packet * doesn’t seem to work. The following is what 
gets printed on GDB:

//upon packet arrival, check the mac to see if it’s the packet intended for 
extraction
//print the packet
packet_recvd = dp_packet_clone (ctx->xin->packet);
VLOG_ERR("structure of pkt received: %s ", 
ofp_dp_packet_to_string(packet_recvd))

Gdb --> structure of pkt received by deaggr: 
udp,vlan_tci=0x0000,dl_src=00:00:00:00:00:01,dl_dst=00:00:00:00:00:02,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,nw_ecn=0,nw_ttl=64,tp_src=47981,tp_dst=444
 udp_csum:2eb2

//Extract the payload by casting
struct my_captured_packet *checkrecvd = (struct my_captured_packet *) 
dp_packet_get_udp_payload(packet_recvd);

VLOG_ERR("structure of first packet extracted from buffer: %s with size_ of 
%d", ofp_dp_packet_to_string(&checkrecvdAggr[0].packet),  
checkrecvdAggr[0].packet.size_);

Gdb--> structure of first packet extracted from buffer:  
packet_type=(0x302c,0x646c) //this should be a normal structured dp_packet

with size_ of 21299712 //size seems abnormal

I’ve tried this whole algorithm by sending a normal packet received without 
creating a new one and it works, so I’m guessing the problem is still in how I 
structure my custom packet, so my question is what am I missing in order to 
create a valid custom UDP packet that is sendable from OVS? Can I find examples 
anywhere in the codebase? I haven’t seen anything to be honest.
Help is really needed!

Thanks,

Luca













_______________________________________________
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss

Reply via email to