def rewrite_space(spaces): ''' Rewrite hs, ports lists to have a single port per item ''' ports = set([p for s, ps in spaces for p in ps]) for p in ports: hs = headerspace(HEADER_LENGTH / 4) for space, sports in spaces: if p in sports: hs.add_hs(space) yield (hs, [p])
from headerspace import * from headerspace.tf import * from headerspace.hs import * from dynamicscc import DynamicSCC from statsbuddy import StatsBuddy, Buckets from collections import defaultdict from Queue import Queue # this is the length of header that all rules will be expecting and requiring HEADER_LENGTH = 24 # this should be a multiple of 4 ALLMASK = "x" * (HEADER_LENGTH) ONEMASK = "1" * (HEADER_LENGTH) ZEROMASK = "0" * (HEADER_LENGTH) HEADERSPACE_ALL = headerspace(HEADER_LENGTH / 4) HEADERSPACE_ALL.add_hs(hs_string_to_byte_array(ALLMASK)) # this tries to change the grouping of space, port pairs in the loop detection code to reduce the depth of the search. TRY_EFFICIENCY_TWEAK = False def pad_to_header_length(string=None, num=None, size=None): ''' Encode string or num into a binary string of length HEADER_LENGTH. The size parameter is used for input num, to indicate that the input number should occupy the first 'size' bits of the resulting encoded string ''' if string == None: assert num is not None and size is not None string = bin(num)[2:]