Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Introduce new options cluster_id and cpu_affinity #8

Merged
merged 1 commit into from

2 participants

@ates
Collaborator

Hey Michael,

This patch adds the complete pf_ring support to epcap.
Also adds the new option cpu_affinity to link epcap process to specific CPU (using taskset).

Hope this will be useful.

Thanks.

@msantos
Owner

Thanks!

@msantos msantos merged commit 77aac45 into msantos:master
@ates
Collaborator

Michael, looks like I forgot to delete the unnecessary debug message in line 68 of epcap.erl:

io:format("CMD: ~p~n", [Cmd]),

Could you please remove it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 23, 2012
  1. @ates
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 6 deletions.
  1. +10 −1 README.md
  2. +25 −5 src/epcap.erl
View
11 README.md
@@ -41,7 +41,7 @@ epcap includes a small example program called sniff.
Types Args = [Options]
Options = {chroot, string()} | {group, string()} | {interface, string()} | {promiscuous, boolean()} |
{user, string()} | {filter, string()} | {progname, string()} | {file, string()} |
- {monitor, boolean()}
+ {monitor, boolean() | {cpu_affinity, string()} | {cluster_id, non_neg_integer()}}
Packets are delivered as messages:
@@ -70,6 +70,15 @@ epcap includes a small example program called sniff.
As a result epcap binary will be linked with the following flags: -static -lpfring -lpthread
+ To complete the configuration you need to set up the cluster_id option.
+ The value of the cluster_id option is integer and should be in range between 0 and 255.
+
+ epcap:start([{interface, "lo"}, {cluster_id, 2}]).
+
+ You can also specify the option cpu_affinity to set up CPU affinity for epcap port:
+
+ epcap:start([{interface, "lo"}, {cluster_id, 2}, {cpu_affinity, "1,3,5-7"}]).
+
## SCREENSHOT
View
30 src/epcap.erl
@@ -65,6 +65,7 @@ init([Pid, Options]) ->
_ -> 500
end,
Cmd = make_args(Options ++ [{chroot, Chroot}, {timeout, Timeout}]),
+ io:format("CMD: ~p~n", [Cmd]),
Port = open_port({spawn, Cmd}, [{packet, 2}, binary, exit_status]),
{ok, #state{pid = Pid, port = Port}}.
@@ -108,7 +109,7 @@ make_args(PL) ->
true -> "";
false -> "sudo "
end,
- proplists:get_value(progname, PL, Sudo ++ progname()) ++ " " ++
+ proplists:get_value(progname, PL, Sudo ++ pfring(PL) ++ cpu_affinity(PL) ++ progname()) ++ " " ++
string:join([get_switch(proplists:lookup(Arg, PL)) || Arg <- [
chroot,
group,
@@ -120,9 +121,9 @@ make_args(PL) ->
snaplen,
timeout,
verbose,
-
- filter
- ], proplists:lookup(Arg, PL) /= none ], " ").
+ filter,
+ pfring
+ ], proplists:lookup(Arg, PL) /= none], " ").
get_switch({chroot, Arg}) -> "-d " ++ Arg;
get_switch({file, Arg}) -> "-f " ++ Arg;
@@ -136,9 +137,10 @@ get_switch({user, Arg}) -> "-u " ++ Arg;
get_switch({verbose, Arg}) -> string:copies("-v ", Arg);
get_switch({filter, Arg}) -> "\"" ++ Arg ++ "\"".
+-spec basedir() -> string().
basedir() ->
case code:priv_dir(?MODULE) of
- {error,bad_name} ->
+ {error, bad_name} ->
filename:join([
filename:dirname(code:which(?MODULE)),
"..",
@@ -149,8 +151,26 @@ basedir() ->
Dir
end.
+-spec progname() -> string().
progname() ->
filename:join([basedir(), ?MODULE]).
+-spec chroot_path() -> string().
chroot_path() ->
filename:join([basedir(), "tmp"]).
+
+-spec pfring([proplists:property()]) -> string().
+pfring(Options) ->
+ case proplists:get_value(cluster_id, Options) of
+ undefined -> "";
+ Value ->
+ "PCAP_PF_RING_CLUSTER_ID=" ++ integer_to_list(Value) ++ " "
+ end.
+
+-spec cpu_affinity([proplists:property()]) -> string().
+cpu_affinity(Options) ->
+ case proplists:get_value(cpu_affinity, Options) of
+ undefined -> "";
+ CPUs ->
+ "taskset -c " ++ CPUs ++ " "
+ end.
Something went wrong with that request. Please try again.