headerspace Package

applications Module

Created on Jan 27, 2011

@author: peyman kazemian

sts.headerspace.headerspace.applications.compute_omega(name_tf_pairs, TTF, edge_links)[source]
sts.headerspace.headerspace.applications.compute_single_omega(start_port, edge_ports)[source]
sts.headerspace.headerspace.applications.detect_loop(NTF, TTF, ports, test_packet=None)[source]
sts.headerspace.headerspace.applications.find_blackholes(NTF, TTF, edge_links, test_packet=None)[source]
Do any switches:
  • send packets into a down link?
  • drop packets that are supposed to go out their in_port?

Specifically, checks whether it’s possible for any packets to fall into the blackhole in the first place.

sts.headerspace.headerspace.applications.find_loop_original_header(NTF, TTF, propagation_node)[source]
sts.headerspace.headerspace.applications.find_reachability(NTF, TTF, edge_links, test_packet=None)[source]
sts.headerspace.headerspace.applications.get_all_x(NTF)[source]
sts.headerspace.headerspace.applications.invoke_hassel_c(start_port, edge_ports)[source]

invoke reachability test, and return the proc object

sts.headerspace.headerspace.applications.loop_path_to_str(p_node, reverse_map)[source]
sts.headerspace.headerspace.applications.prepare_hassel_c(name_tf_pairs, TTF)[source]
sts.headerspace.headerspace.applications.print_loops(loops, reverse_map)[source]
sts.headerspace.headerspace.applications.print_p_node(p_node)[source]
sts.headerspace.headerspace.applications.print_reachability(paths, reverse_map)[source]
sts.headerspace.headerspace.applications.trace_hs_back(applied_rule_list, hs, last_port)[source]
sts.headerspace.headerspace.applications.translate_ports(ports)[source]

hs Module

Created on Jan 24, 2011

@author: peyman kazemian

sts.headerspace.headerspace.hs.byte_array_and(b1, b2)[source]

perform ‘and’ operation when b1 and b2 can have wildcard bits

sts.headerspace.headerspace.hs.byte_array_complement(a)[source]

a’

sts.headerspace.headerspace.hs.byte_array_difference(a, b)[source]

‘ a - b = a n b’

sts.headerspace.headerspace.hs.byte_array_equal(a1, a2)[source]

checks if a1=a2.

sts.headerspace.headerspace.hs.byte_array_get_all_one(length)[source]
sts.headerspace.headerspace.hs.byte_array_get_all_x(length)[source]
sts.headerspace.headerspace.hs.byte_array_get_all_zero(length)[source]
sts.headerspace.headerspace.hs.byte_array_get_bit(b_array, byte, bit)[source]
sts.headerspace.headerspace.hs.byte_array_intersect(a1, a2)[source]

a1 n a2.

sts.headerspace.headerspace.hs.byte_array_list_contained_in(list_a, list_b)[source]
sts.headerspace.headerspace.hs.byte_array_not(b)[source]

perform ‘or’ operation when b1 and b2 can have wildcard bits

sts.headerspace.headerspace.hs.byte_array_or(b1, b2)[source]

perform ‘or’ operation when b1 and b2 can have wildcard bits

sts.headerspace.headerspace.hs.byte_array_set_bit(b_array, byte, bit, value)[source]
sts.headerspace.headerspace.hs.byte_array_set_bytes(b_array, byte, value, num_bytes)[source]
sts.headerspace.headerspace.hs.byte_array_subset(a, b)[source]

checks if a is subset of b. doesn’t work if a is empty

sts.headerspace.headerspace.hs.byte_array_to_hs_string(byte_array)[source]
sts.headerspace.headerspace.hs.byte_array_to_pretty_hs_string(byte_array)[source]
sts.headerspace.headerspace.hs.byte_has_no_x(b)[source]
sts.headerspace.headerspace.hs.byte_to_int(b)[source]
sts.headerspace.headerspace.hs.bytes_all_x(bytes)[source]
sts.headerspace.headerspace.hs.bytes_to_int(bytes)[source]
class sts.headerspace.headerspace.hs.headerspace(hsa_format)[source]

Bases: object

A headerspace object keeps a set of header space regions. it can be union of [0,1,x,z] expressions. It can also keep a list of headerspaces to be subtracted from this object. The subtraction can be done lazily. It also enables normal set operations on header space.

__init__(hsa_format)[source]

Constructor

add_hs(value)[source]

adds value to the list of headerspaces, hs_list @value: bytearray of lenght self.length or another headerspace objects @return: True if successful, False otherwise

add_hs_list(values)[source]

adds values to the list of headerspaces, hs_list @values: list of bytearray of lenght self.length or other headerspace objects @return: True

add_lazy_tf_rule(ntf, rule_id, port)[source]
apply_lazy_tf_rule()[source]
clean_up()[source]
complement()[source]

find the complement of header space pieces saved in hs_list and saves it back to itself

compress()[source]

‘ TODO: Compress function need to consider more cases Warning: depreciated

copy()[source]

create a deep copy of itself

copy_complement()[source]
copy_intersect(other_hs)[source]
copy_minus(other_fs)[source]
count()[source]

returns count of number of elements in hs_list

count_dif()[source]

returns count of number of elements in hs_dif

diff_hs(value)[source]

lazily subtract value from this headerspace @value: bytearray of lenght self.length @return: True if successful, False otherwise

diff_hs_list(values)[source]

lazily subtract values from this headerspace @values: list of bytearray of lenght self.length @return: True

intersect(other_hs)[source]

intersect itself with other_hs if the header lengths are equal. The result will be saved in the caller instance itself. @other_fs: @type headerspace or bytearray: the other headerspace to intersect with @return: @type Boolean: True if successful, False if an error happens

is_subset_of(other_fs)[source]

checks if self is a subset of other_hs

minus(other_fs)[source]

computes self - other_fs. note that the hs_diff will be intact

pop_applied_tf_rule()[source]
push_applied_tf_rule(ntf, rule_id, in_port)[source]
self_diff()[source]

computes hs_list - hs_diff and saves all the result in hs_list.

to_string()[source]

represent a [0,1,x,z] string showing the header space.

sts.headerspace.headerspace.hs.hs_string_to_byte_array(str)[source]
sts.headerspace.headerspace.hs.hsa_bit_to_normal_bit(bit)[source]
sts.headerspace.headerspace.hs.int_to_byte_array(int_value, len)[source]

reads len bits from int_value and converts it to a bytearray of len ceil(len/4). Note: len should be a multiple of 4.

slice Module

Created on Jan 26, 2011

@author: peymankazemian

class sts.headerspace.headerspace.slice.Slice(length)[source]

Bases: object

classdocs

__init__(length)[source]

Constructor

get_port_reservation(port)[source]
intersect(other_slice)[source]
set_hs_reservation(ports, hs)[source]

set hs reservation on @port to new_hs NOTE: hs.hs_list MUST have only one wildcard expression

test_hs Module

Created on Jun 20, 2011

@author: peymankazemian

sts.headerspace.headerspace.test_hs.test_hs_simple()[source]

test_ip_compress Module

Created on Jul 27, 2011

@author: peymankazemian

test_ip_tf Module

Created on Aug 18, 2011

@author: peymankazemian

test_tf Module

Created on Jun 20, 2011

@author: peymankazemian

sts.headerspace.headerspace.test_tf.convert(ipsi, ipei)[source]
sts.headerspace.headerspace.test_tf.test_tf_simple()[source]

tf Module

Created on Jan 24, 2011

@author: peyman kazemian

class sts.headerspace.headerspace.tf.TF(hsa_format)[source]

Bases: object

models a box transfer function, a network transfer function or a topology transfer function

T(hs, port)[source]

returns a list of (hs, list of output ports) as a result of applying transfer function. hs will have A-B format, where A is the intersection of hs and the rule’s match struct and B will be union of match bytes of all the rules that influence on the matching rule.

T_inv(hs, port)[source]

returns a list of (hs, list of in_ports) as possible inputs that can cause this (hs,port). The format of hs and returned headerspace object, is like T() method above.

T_inv_rule(rule_id, hs, port)[source]

Apply rule with id = rule_id to (hs,port) Output is a list of [hs,list_of_out_ports].

T_rule(rule_id, hs, port)[source]

Apply rule with id = rule_id to (hs,port) Output is a list of [hs,list_of_out_ports].

__init__(hsa_format)[source]

Constructor

activate_hash_table(nibble_indices)[source]
activate_lazy_eval()[source]
add_custom_rule(rule, priority=-1)[source]

Add a custom rule. You need to provide a function for finding math and a function for creating output header. rule should have the following entries: * ‘match’: a pointer to the function for finding if a packet match this rule. the function should accept (headerspace,in_port) as input and returns a list of headerspace objects that match this rule * ‘transform’: a pointer to a function which outputs a list of (headerspace, list of out_ports) pairs as the output of the rule. * ‘inv_match’: a pointer to the function for finding if an output packet can be generated by this rule. The function format is like “match’. * ‘inv_transform’: a pointer to a function which outputs a list of (headerspace, list of in_ports) pairs as the output of the inverse rule. WARNING: use custom rules in a transfer function with only custom rules. Interaction between custom rules and rewrite/fw rules is not defined.

add_fwd_rule(rule, priority=-1)[source]
  • ‘match’: a bytearray of length self.length describing the header formats that

match this rule. * ‘in_ports’: the list of input port numbers to match on * ‘out_ports’: the list of output port numbers.

This is useful for topology transfer fucntions * ‘in_ports’: the list of input port numbers to match on * ‘out_port’: the list of output port numbers. WARNING: Use link rule only in Topology Transfer Function. Don’t mix it with other type of rules.

add_rewrite_rule(rule, priority=-1)[source]

rule is a dictionary with following keys: * ‘match’: a bytearray of length self.length describing the header formats that match this rule. * ‘in_ports’: the list of input port numbers to match on * ‘mask’: a bytearray of length self.length that masks all the bits that won’t be rewritten * ‘rewrite’: a bytearray of length self.length that rewrites the desired bits. * ‘out_ports’: the list of output port numbers.

apply_custom_rule(rule, hs, port)[source]
apply_fwd_rule(rule, hs, port, applied_rules=None)[source]
apply_inv_custom_rule(rule, hs, port)[source]
apply_inv_fwd_rule(rule, hs, port)[source]
apply_inv_rewrite_rule(rule, hs, port)[source]
apply_rewrite_rule(rule, hs, port, applied_rules=None)[source]
static create_custom_rule(match, transform, inv_match, inv_transform, file_name, lines)[source]
static create_multirewrite_rule(in_ports, match, rules)[source]

creates a rule that if matches on in_ports, match, does all the actions in rules. the in_ports,matches in rules will be the same as in_ports, match in the multi-rewrite rule.

static create_standard_rule(in_ports, match, out_ports, mask, rewrite, file_name='', lines=[])[source]

Create a rule using input arguments. Use None if an input is not applicable.

deactivate_hash_table()[source]
deactivate_lazy_eval()[source]
find_influences(priority)[source]

After inserting the new_rule, into self.rules, call this method to update the rule dependencies. @priority: priority or position of the new rule in the table

generate_next_id()[source]
hs_string(byte_array)[source]
inv_to_string()[source]
is_qualified_for_lazy_eval(rule)[source]

This is a simple version of checking for lazy evaluation. TODO: implement a more complex version that understand packet header rather than just looking at some bit positions

load_object_from_file(file)[source]

load object from file, and replace the current object.

print_influences()[source]

For each rule, shows the list of higher priority rules that has an intersection with the rule, and also the lower priority rules that has an intersection with the rule, in two separate lists.

save_object_to_file(file)[source]

saves all the non-custom transfer function rules to a file

set_fast_lookup_pointers(priority)[source]
set_lazy_evaluate(list_of_nibbles)[source]
set_prefix_id(str_prefix)[source]
set_send_on_receiving_port(val)[source]
static standard_rule_to_string(std_rule)[source]
to_string()[source]
sts.headerspace.headerspace.tf.port_to_hex(port)[source]
sts.headerspace.headerspace.tf.ports_to_hex(ports)[source]

wildcard_dictionary Module

Created on Sep 13, 2011

@author: peymankazemian

class sts.headerspace.headerspace.wildcard_dictionary.wildcard_dictionary(num_key_bits, threshold)[source]

Bases: object

classdocs

__init__(num_key_bits, threshold)[source]

TODOC: What does threshold do?

add_entry(keys, value)[source]
add_entry_to_table(table, key, value, next_keys)[source]
find_entry(keys)[source]
find_entry_in_table(table, keys)[source]
self_print()[source]
self_print_table(table, indent)[source]