from headerspace.hs import headerspace from time import time from random import choice def generate_random_wc(): r = ["1", "0", "x"] result = "" for i in range(8): sym = choice(r) result += sym return result if __name__ == '__main__': N = NetPlumber(1) rule_ids = [] N.add_link(2, 4) N.add_link(4, 2) N.add_link(3, 6) N.add_link(6, 3) N.add_link(5, 8) N.add_link(8, 5) N.add_link(7, 9) N.add_link(9, 7) N.add_link(1, 100) N.add_link(100, 1) s = headerspace(1) s.add_hs(wildcard_create_from_string("1xxxxxxx")) N.add_source("client", s, [100]) st = time()
def setUp(self): ''' topology: box1: 1,2,3 box2: 4,5,10 box3: 6,7,11 box4: 8,9,12 2<-->4 3<-->6 5<-->8 7<-->9 box1: (1010xxxx,1) --> (1010xxxx,2) (10001xxx,1) --> (10000xxx,2) (10xxxxxx,[1,2]) --> (10xxxxxx,3) box2: (1011xxxx,4) --> (10101xxx,5) (10xxxxxx,4) --> (111xxxxx,5) box 3: (101xxxxx,[6,11]) --> (101xx111,7) box 4: (xxx010xx,8) --> (xxx010xx,12) ''' self.N = NetPlumber(1) self.rule_ids = [] self.N.add_link(2,4) self.N.add_link(4, 2) self.N.add_link(3, 6) self.N.add_link(6, 3) self.N.add_link(5, 8) self.N.add_link(8, 5) self.N.add_link(7, 9) self.N.add_link(9, 7) self.rule_ids.append(self.N.add_rule("B1", -1, [1], [2], \ wildcard_create_from_string("1010xxxx"), \ None, \ None)) self.rule_ids.append(self.N.add_rule("B1", -1, [1], [2], \ wildcard_create_from_string("10001xxx"), \ None, \ None)) self.rule_ids.append(self.N.add_rule("B1", -1, [1,2], [3], \ wildcard_create_from_string("10xxxxxx"), \ None, \ None)) self.rule_ids.append(self.N.add_rule("B2", -1, [4], [5], \ wildcard_create_from_string("1011xxxx"), \ wildcard_create_from_string("11100111"), \ wildcard_create_from_string("00001000"))) self.rule_ids.append(self.N.add_rule("B2", -1, [4], [5], \ wildcard_create_from_string("10xxxxxx"), \ wildcard_create_from_string("10011111"), \ wildcard_create_from_string("01100000"))) self.rule_ids.append(self.N.add_rule("B3", -1, [6,11], [7], \ wildcard_create_from_string("101xxxxx"), \ wildcard_create_from_string("11111000"), \ wildcard_create_from_string("00000111"))) self.rule_ids.append(self.N.add_rule("B4", -1, [8], [12], \ wildcard_create_from_string("xxx010xx"), \ None, \ None))
cisco_router.SWITCH_ID_MULTIPLIER, "port_type_multiplier": cisco_router.PORT_TYPE_MULTIPLIER, "mid_port_type_const": cisco_router.INTERMEDIATE_PORT_TYPE_CONST, } loader = net_loader(settings) (map, inv_map) = loader.load_port_map() #topology f = TF(1) f.load_object_from_file("%s/topology.tf" % settings["input_path"]) #net plumber instance N = NetPlumber(f.length) #adding links for rule in f.rules: input_ports = rule["in_ports"] output_ports = rule["out_ports"] for input_port in input_ports: for output_port in output_ports: N.add_link(input_port, output_port) # add links for intermediate port f = open("%s/port_map.txt" % settings["input_path"], 'r') for line in f: if (not line.startswith("$")) and line != "": tokens = line.strip().split(":") port = int(tokens[1]) + settings["port_type_multiplier"] * \