1 ---------------------------------
 
    2 --- @file distribute.lua
 
    3 --- @brief Distribute ...
 
    5 ---------------------------------
 
    7 local 
ffi = require 
"ffi" 
    8 local dpdk = require 
"dpdk" 
    9 local serpent = require 
"Serpent" 
   12 struct mg_distribute_queue{
 
   15   struct rte_mbuf *pkts[0];
 
   18 struct mg_distribute_output{
 
   23   uint64_t time_first_added;
 
   24   struct mg_distribute_queue *queue;
 
   27 struct mg_distribute_config{
 
   28   uint16_t entry_offset;
 
   31   struct mg_distribute_output outputs[0];
 
   35 inline int8_t mg_distribute_enqueue(
 
   36   struct mg_distribute_queue * queue,
 
   39   queue->pkts[queue->next_idx] = 
pkt;
 
   44   if(unlikely(queue->next_idx == queue->size)){
 
   47   if(unlikely(queue->next_idx == 1)){
 
   53 struct mg_distribute_config * mg_distribute_create(
 
   54     uint16_t entry_offset,
 
   59 int mg_distribute_output_flush(
 
   60   struct mg_distribute_config *cfg,
 
   64 int mg_distribute_register_output(
 
   65   struct mg_distribute_config *cfg,
 
   73 int mg_distribute_send(
 
   74   struct mg_distribute_config *cfg,
 
   75   struct rte_mbuf **pkts,
 
   76   struct mg_bitmask* pkts_mask,
 
   80 void mg_distribute_handle_timeouts(
 
   81   struct mg_distribute_config *cfg
 
   88 local mg_distribute = {}
 
   89 mod.mg_distribute = mg_distribute
 
   90 mg_distribute.__index = mg_distribute
 
   93 function mod.createDistributor(socket, entryOffset, nrOutputs, alwaysFlush)
 
   94   socket = socket or select(2, dpdk.getCore())
 
   95   entryOffset = entryOffset or 0
 
  102   return setmetatable({
 
  103     cfg = 
ffi.gc(
ffi.C.mg_distribute_create(entryOffset, nrOutputs, alwaysFlush), 
function(
self)
 
  105       ffi.C.mg_NOT_YET_IMPLEMENTED(
self) -- FIXME
 
  112 function mg_distribute:__serialize()
 
  113     return "require 'distribute'; return " .. serpent.addMt(serpent.dumpRaw(self), "require('distribute').mg_distribute"), true
 
  116 function mg_distribute:send(packets, bitMask, routingEntries)
 
  117   return 
ffi.C.mg_distribute_send(self.cfg, packets.array, bitMask.bitmask, 
ffi.cast("
void **", routingEntries.array))
 
  120 function mg_distribute:registerOutput(outputNumber, txQueue, bufferSize, timeout)
 
  121   -- FIXME: is this a good idea, to use uint64_t bit integers in lua??
 
  123   local cycles_timeout = tonumber(f_cpu * timeout)
 
  125   local portID = txQueue.
id 
  126   local queueID = txQueue.qid
 
  128   print ("register output NR " .. tostring(outputNumber) .. " -> port = " .. tostring(portID) .. " queue = " .. tostring(queueID) .. " timeout = " .. tostring(cycles_timeout))
 
  129   ffi.C.mg_distribute_register_output(self.cfg, outputNumber, portID, queueID, bufferSize, cycles_timeout)
 
  132 function mg_distribute:handleTimeouts()
 
  133   ffi.C.mg_distribute_handle_timeouts(self.cfg)
 
local ffi
low-level dpdk wrapper 
 
local mod
high-level dpdk wrapper 
 
function mod getCyclesFrequency()
get the TSC frequency 
 
local pkt
Module for packets (rte_mbuf)