kohler / click

The Click modular router: fast modular packet processing and analysis
Other
735 stars 322 forks source link

elementclass access to global element #425

Open miladghaznavi opened 5 years ago

miladghaznavi commented 5 years ago

Is there a way to access to an element defined in global space inside the definition of an elementclass. For instance:

// Defining global element 'nat'
// I want to access this element in the element class NFBlock defined further below
nat::IPAddrRewriter(pattern 1.0.0.0-1.0.127.254 - 0 0,
    pattern 1.0.127.255-1.0.255.255 - 1 1)

// element class NFBlock definition
elementclass NFBlock {
$src_ip, $port |
    input
    -> MarkIPHeader(14)
    -> IPFilter(allow udp && src 1.0.0.0/16)
    -> [$port]nat[$port] // referring to the global element 'nat'
    -> MarkIPHeader(14)
    -> StoreIPAddress($src_ip, src)
    -> output
}

// From device declarations
fd0::FromDPDKDevice(1, 0);
fd1::FromDPDKDevice(1, 1);

// To device declarations
td0::ToDPDKDevice(1, 0);
td1::ToDPDKDevice(1, 1);

// Scheduling
StaticThreadSched(fd0 0, fd1 1);

// NF Block declarations
nfb0::NFBlock(1.1.0.0, 0);
nfb1::NFBlock(1.1.1.0, 1);

// Queue 0
fd0
-> nfb0
-> td0;

// Queue 1
fd1
-> nfb1
-> td1;
tbarbette commented 5 years ago

The global reference is valid in the element. However getting out and back of the elementclass is not possible. It only have input and outputs. The usual solution would be to have one more output and one more input that would be piped "externally" to nat.

Eg in your element class replace [$port]nat[$port] by output[1] ; input[1] and add nfb[1] -> nat ->[1]nfb0 ; nfb[1] -> [1]nat[1] -> [1]nfb0 ;somewhere.