simnet
Class SimpleFilter

java.lang.Object
  extended bysimnet.IPFilter
      extended bysimnet.SimpleFilter
All Implemented Interfaces:
Pluggable

public class SimpleFilter
extends IPFilter
implements Pluggable

A simple implementation of a set of rules and BPF filters. Rules are run in order by number until a match is found, and the allow/deny of that rule determines action. For packets that are allowed, all BPFs are run on them.


Field Summary
 Vektor bpfs
          The Vector that holds this Filter' s BPF rules
private  java.util.Hashtable removeHash
           
 java.util.TreeSet rules
          This Filer' s rule list
 
Fields inherited from class simnet.IPFilter
id
 
Constructor Summary
SimpleFilter()
           
 
Method Summary
 void addBPF(BPF bpf)
          Adds the specified BPF rule to the BPF table.
 void addRule(int rule_id, int action, int protocol, int src_id, int dest_id, int dest_port)
          Adds a rule with the specified fields to this Filter's rule list.
 void addRule(Rule rule)
          Adds the specified rule to this Filter' s rule list.
 boolean in(IP_Packet ipp)
          Processes incoming IP packets by checking them against each Rule in increasing order of their IDs.
 void initialize(int filter_id)
          Initializes a new SimpleFilter by initializing its ID and default rules.
 boolean prePlugout(java.lang.Object replacement)
          No special cleanup is needed.
 void removeBPF(BPF bpf)
          Removes the specified BPF rule from the BPF table.
 void removeRule(int rid)
          Removes the Rule with the specified ID from the rule list.
 java.lang.String toString()
          Returns a String listinag all of this Filter's Rules.
 
Methods inherited from class simnet.IPFilter
finalize
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rules

public java.util.TreeSet rules
This Filer' s rule list


bpfs

public Vektor bpfs
The Vector that holds this Filter' s BPF rules


removeHash

private java.util.Hashtable removeHash
Constructor Detail

SimpleFilter

public SimpleFilter()
Method Detail

initialize

public void initialize(int filter_id)
Initializes a new SimpleFilter by initializing its ID and default rules.

Specified by:
initialize in class IPFilter
Parameters:
filter_id - the ID of this filter

in

public boolean in(IP_Packet ipp)
Processes incoming IP packets by checking them against each Rule in increasing order of their IDs. The action determined by the first rule that matches the packet is taken.

Specified by:
in in class IPFilter
Parameters:
ipp - the incoming IP packet
Returns:
TRUE if the packet matches a rule with an ALLOW action; FALSE if it matches a packet with a DENY action or if it does not match any rule at all

addRule

public void addRule(Rule rule)
Adds the specified rule to this Filter' s rule list.

Specified by:
addRule in class IPFilter
Parameters:
rule - the rule to add

addRule

public void addRule(int rule_id,
                    int action,
                    int protocol,
                    int src_id,
                    int dest_id,
                    int dest_port)
Adds a rule with the specified fields to this Filter's rule list.

Specified by:
addRule in class IPFilter
Parameters:
rule_id - the unique ID of this Rule
action - the action to take when a packet has been matched (either Simnet.ALLOW or Simnet.DENY)
protocol - the Rule' s protocol
src_id - the Rule' s source Node
dest_id - the Rule's destination Node
dest_port - the Rule' s destination port

removeRule

public void removeRule(int rid)
Removes the Rule with the specified ID from the rule list. Note: the TreeSet.remove() method only takes objects, so in order to delete an object from the Tree, we need to keep a pointer to that object. However all we have is the ID, so we keep track of the objects and their IDs in a hashtable. This isn' t very elegant but it works.

Specified by:
removeRule in class IPFilter
Parameters:
rid - The Rule's ID

addBPF

public void addBPF(BPF bpf)
Adds the specified BPF rule to the BPF table.

Specified by:
addBPF in class IPFilter
Parameters:
bpf - the BPF rule to add

removeBPF

public void removeBPF(BPF bpf)
Removes the specified BPF rule from the BPF table.

Specified by:
removeBPF in class IPFilter
Parameters:
bpf - the BPF rule to remove

toString

public java.lang.String toString()
Returns a String listinag all of this Filter's Rules.


prePlugout

public boolean prePlugout(java.lang.Object replacement)
No special cleanup is needed.

Specified by:
prePlugout in interface Pluggable
Returns:
if this object can now be removed (was the operation sucessful)