-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added a reusable packet filtering tree - Added the filter to the monitoring module as an option - Created the packet_filter project for demonstration purposes of the packet filtering tree Signed-off-by: Istvan-Zsolt Szekely <[email protected]>
- Loading branch information
1 parent
9770fd6
commit e32d8e8
Showing
26 changed files
with
826 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
`include "utils.svh" | ||
|
||
package filter_pkg; | ||
|
||
import logger_pkg::*; | ||
|
||
class filter_class; | ||
|
||
protected bit [31:0] position; | ||
protected logic [7:0] value; | ||
protected bit equals; | ||
|
||
bit result; | ||
|
||
function new( | ||
input bit [31:0] position, | ||
input logic [7:0] value, | ||
input bit equals = 1); | ||
|
||
this.position = position; | ||
this.value = value; | ||
this.equals = equals; | ||
this.result = 0; | ||
endfunction: new | ||
|
||
function void apply_filter(input logic [7:0] packet[]); | ||
logic [7:0] value; | ||
|
||
value = packet[this.position]; | ||
for (int i=0; i< $size(value); i++) | ||
if (this.value[i] == 1'bx || this.value[i] == 1'bz) continue; | ||
else if (this.value[i] != value[i]) begin | ||
this.result = !equals; | ||
return; | ||
end | ||
|
||
this.result = equals; | ||
return; | ||
endfunction: apply_filter | ||
|
||
endclass: filter_class | ||
|
||
|
||
class filter_tree_class; | ||
|
||
protected bit filter_type; // 0 - all leaf nodes/cells are evaluated with logical or | ||
// 1 - all leaf nodes/cells are evaluated with logical and | ||
|
||
bit result; | ||
|
||
protected filter_class filter[]; | ||
filter_tree_class ft[]; | ||
|
||
function new( | ||
input bit filter_type, | ||
input bit [31:0] nr_of_filters, | ||
input bit [31:0] nr_of_filter_trees); | ||
|
||
this.filter_type = filter_type; | ||
this.result = filter_type; | ||
this.filter = new[nr_of_filters]; | ||
this.ft = new[nr_of_filter_trees]; | ||
endfunction: new | ||
|
||
function void add_filter( | ||
input bit [31:0] filter_nr, | ||
input bit [31:0] position, | ||
input logic [7:0] value, | ||
input bit equals = 1); | ||
|
||
this.filter[filter_nr] = new (position, value, equals); | ||
endfunction: add_filter | ||
|
||
function void add_filter_tree( | ||
input bit [31:0] filter_tree_nr, | ||
input bit filter_type, | ||
input bit [31:0] nr_of_filters, | ||
input bit [31:0] nr_of_filter_trees); | ||
|
||
this.ft[filter_tree_nr] = new (filter_type, nr_of_filters, nr_of_filter_trees); | ||
endfunction: add_filter_tree | ||
|
||
function void remove_filters(); | ||
this.filter = new[0]; | ||
this.ft = new[0]; | ||
endfunction: remove_filters | ||
|
||
task apply_filter(input logic [7:0] packet[]); | ||
if (this.filter != null) begin | ||
for (int i=0; i<this.filter.size(); i++) begin | ||
this.filter[i].apply_filter(packet); | ||
end | ||
for (int i=0; i<this.filter.size(); i++) begin | ||
if (filter_type) | ||
this.result = this.result & this.filter[i].result; | ||
else | ||
this.result = this.result | this.filter[i].result; | ||
end | ||
end | ||
|
||
if (this.ft != null) begin | ||
for (int i=0; i<this.ft.size(); i++) begin | ||
this.ft[i].apply_filter(packet); | ||
end | ||
for (int i=0; i<this.ft.size(); i++) begin | ||
if (filter_type) | ||
this.result = this.result & this.ft[i].result; | ||
else | ||
this.result = this.result | this.ft[i].result; | ||
end | ||
end | ||
endtask: apply_filter | ||
|
||
endclass: filter_tree_class | ||
|
||
endpackage: filter_pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.