コード例 #1
0
ファイル: test_tf.py プロジェクト: 0xdyu/VeriExodus
 def testFwd(self):
     tf = TF(1)
     tf.add_fwd_rule(TF.create_standard_rule([1], "10xxxxxx", [2], None, None))
     hs = headerspace(1)
     hs.add_hs(wildcard_create_from_string("1001xxxx"))
     result = tf.T(hs, 1)
     self.assertEqual(len(result), 1)
     self.assert_(wildcard_is_equal(result[0][0].hs_list[0], wildcard_create_from_string("1001xxxx")))
コード例 #2
0
ファイル: test_tf.py プロジェクト: oceanly020/hassel-op
 def testFwd(self):
     tf = TF(1)
     tf.add_fwd_rule(TF.create_standard_rule([1], "10xxxxxx", [2], \
                                             None, None))
     hs = headerspace(1)
     hs.add_hs(wildcard_create_from_string("1001xxxx"))
     result = tf.T(hs, 1)
     self.assertEqual(len(result), 1)
     self.assert_(wildcard_is_equal(result[0][0].hs_list[0],\
                                    wildcard_create_from_string("1001xxxx")))
コード例 #3
0
ファイル: test_tf.py プロジェクト: 0xdyu/VeriExodus
 def testDependency(self):
     tf = TF(1)
     tf.add_fwd_rule(TF.create_standard_rule([1], "10xxxxxx", [2], None, None))
     tf.add_rewrite_rule(TF.create_standard_rule([1], "1xxxxxxx", [3], "00111111", "10000000", "", []))
     hs = headerspace(1)
     hs.add_hs(wildcard_create_from_string("xxxxxxxx"))
     result = tf.T(hs, 1)
     self.assertEqual(len(result), 2, "Expecting both rules to be matched")
     self.assertTrue(
         wildcard_is_equal(result[1][0].hs_list[0], wildcard_create_from_string("10xxxxxx")),
         "unexpected second byte array",
     )
コード例 #4
0
ファイル: test_tf.py プロジェクト: oceanly020/hassel-op
 def testDependency(self):
     tf = TF(1)
     tf.add_fwd_rule(TF.create_standard_rule([1], "10xxxxxx", [2], \
                                             None, None))
     tf.add_rewrite_rule(TF.create_standard_rule([1], "1xxxxxxx", [3], "00111111", "10000000","",[]))
     hs = headerspace(1)
     hs.add_hs(wildcard_create_from_string("xxxxxxxx"))
     result = tf.T(hs, 1)
     self.assertEqual(len(result), 2, "Expecting both rules to be matched")
     self.assertTrue(wildcard_is_equal(
                                      result[1][0].hs_list[0],\
                                      wildcard_create_from_string("10xxxxxx"),\
                                      ), \
                     "unexpected second byte array")
コード例 #5
0
ファイル: ip_star.py プロジェクト: cmarcond/atpg
def make_NTF(num_mbox):
    line_counter = 1
    num_stack = num_mbox + 1
    NTF = TF(format["length"])
    
    m_addr = [dotted_ip_to_int("10.1.1.1"),
              dotted_ip_to_int("10.1.2.2"),
              dotted_ip_to_int("10.1.3.3"),
              dotted_ip_to_int("10.1.4.4"),
              dotted_ip_to_int("10.1.5.5"),]
    m_subnet = [dotted_ip_to_int("10.1.1.0"),
              dotted_ip_to_int("10.1.2.0"),
              dotted_ip_to_int("10.1.3.0"),
              dotted_ip_to_int("10.1.4.0"),
              dotted_ip_to_int("10.1.5.0"),]
    
    sender_addr = dotted_ip_to_int("10.1.10.1")
    receiver_addr = dotted_ip_to_int("10.1.20.1")
    network_subnet = dotted_ip_to_int("10.1.0.0")
    
    # rules for R1
    for i in range(num_mbox):
        ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,m_addr[i],32)
        rule = TF.create_standard_rule([1,7], ip_match, [2], None, None, "sample.txt", [line_counter])
        NTF.add_fwd_rule(rule)
        line_counter += 1
        
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,receiver_addr,32)
    rule = TF.create_standard_rule([1,2], ip_match, [7], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,sender_addr,32)
    rule = TF.create_standard_rule([2,7], ip_match, [1], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1
    
    # Add rule for R2:
    all_ip_star_ingress_ports = []
    for i in range(num_mbox):
        ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,m_addr[i],32)
        rule = TF.create_standard_rule([3,4], ip_match, [14+4*i], None, None, "sample.txt", [line_counter])
        NTF.add_fwd_rule(rule)
        line_counter += 1
        all_ip_star_ingress_ports.append(14+4*i)
    
    for i in range(num_mbox):
        rule = TF.create_custom_rule(make_IP_str_match(all_ip_star_ingress_ports), 
                                     make_IP_str_transform(m_addr[i], 32, [all_ip_star_ingress_ports[i]]), 
                                     make_IP_str_inv_match([all_ip_star_ingress_ports[i]], m_addr[i], 32), 
                                     make_IP_str_inv_transform(all_ip_star_ingress_ports), 
                                     "sample.txt", [line_counter])
        NTF.add_custom_rule(rule)
        line_counter += 1
    rule = TF.create_custom_rule(make_IP_str_match(all_ip_star_ingress_ports), 
                                 make_IP_str_transform(sender_addr, 32, [4]), 
                                 make_IP_str_inv_match([4], sender_addr, 32), 
                                 make_IP_str_inv_transform(all_ip_star_ingress_ports), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
    rule = TF.create_custom_rule(make_IP_str_match(all_ip_star_ingress_ports), 
                                 make_IP_str_transform(receiver_addr, 32, [3]), 
                                 make_IP_str_inv_match([3], receiver_addr, 32), 
                                 make_IP_str_inv_transform(all_ip_star_ingress_ports), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
        
    
    # add rule for R3:
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,receiver_addr,32)
    rule = TF.create_standard_rule([5,6], ip_match, [8], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,sender_addr,32)
    rule = TF.create_standard_rule([5], ip_match, [6], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1    
    rule = TF.create_custom_rule(make_IP_str_match([8]), 
                                 make_IP_str_transform(receiver_addr, 32, [8]), 
                                 make_IP_str_inv_match([8], receiver_addr, 32), 
                                 make_IP_str_inv_transform([8]), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
    rule = TF.create_custom_rule(make_IP_str_match([8]), 
                                 make_IP_str_transform(sender_addr, 32, [6]), 
                                 make_IP_str_inv_match([6], sender_addr, 32), 
                                 make_IP_str_inv_transform([8]), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
    
    for i in range(num_mbox):
        rule = TF.create_custom_rule(make_IP_str_match([8]), 
                                     make_IP_str_transform(m_addr[i], 32, [5]), 
                                     make_IP_str_inv_match([5], m_addr[i], 32), 
                                     make_IP_str_inv_transform([8]), 
                                     "sample.txt", [line_counter])
        NTF.add_custom_rule(rule)
        line_counter += 1
        ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,m_addr[i],32)
        rule = TF.create_standard_rule([6], ip_match, [5], None, None, "sample.txt", [line_counter])
        NTF.add_fwd_rule(rule)
        line_counter += 1 
        
    
    # add rule for R4,R5,R8,R9,...
    for i in range(num_mbox):
        ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,m_subnet[i],24)
        rule = TF.create_standard_rule([15 + 4*i], ip_match, [16 + 4*i], None, None, "sample.txt", [line_counter])
        NTF.add_fwd_rule(rule)
        line_counter += 1 
        ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,network_subnet,18)
        rule = TF.create_standard_rule([16 + 4*i], ip_match, [15 + 4*i], None, None, "sample.txt", [line_counter])
        NTF.add_fwd_rule(rule)
        line_counter += 1 
        
    # add rule for R6
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,receiver_addr,32)
    rule = TF.create_standard_rule([9], ip_match, [10], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1 
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,network_subnet,16)
    rule = TF.create_standard_rule([10], ip_match, [9], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1 
    
    # add rule for R7
    rule = TF.create_custom_rule(make_IP_str_match([11]), 
                                 make_IP_str_transform(receiver_addr, 32, [12]), 
                                 make_IP_str_inv_match([12], receiver_addr, 32), 
                                 make_IP_str_inv_transform([11]), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
    rule = TF.create_custom_rule(make_IP_str_match([11]), 
                                 make_IP_str_transform(network_subnet, 21, [11]), 
                                 make_IP_str_inv_match([11], network_subnet, 21), 
                                 make_IP_str_inv_transform([11]), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
    
    # rule for middle boxes:
    for i in range(num_mbox):
        rule = TF.create_custom_rule(make_mbox_match(m_addr[i], 32, 17+4*i), 
                                     make_mbox_tf(), 
                                     make_mbox_inv_match(m_addr[i], 32, 17+4*i), 
                                     make_mbox_tf(), 
                                     "sample.txt", [line_counter])
        NTF.add_custom_rule(rule)
        line_counter += 1
        
    return NTF
コード例 #6
0
ファイル: tfmod.py プロジェクト: 0xdyu/VeriExodus
if args.view:
    stage = args.view[0]
    i = 1
    for rule in f.rules:
        if stage == get_stage(rule):
            print i,":",get_openflow_rule(rule,inv_mapf)
        i = i + 1;
if args.rm:
    indices = args.rm[0].split(",")
    indices = [int(i) for i in indices]
    indices.sort(reverse=True)
    for index in indices:
        f.remove_rule(index-1)

if args.add:
    positions = (args.add[0]).split(",")
    rules = (args.add[1]).split(":")
    if len(rules) != len(positions):
        sys.stderr.write("Number of positions and number of rules should be the same")
    for i in range(len(positions)):
        position = int(positions[i])-1
        tokens = rules[i].split(";")
        rule = parse_new_rule_tokens(tokens,mapf_extended,args.rtr_name)
        if rule["mask"] == None:
            f.add_fwd_rule(rule,position)
        elif rule["mask"] != None:
            f.add_rewrite_rule(rule,position)

f.save_object_to_file("%s/%s.tf"%(args.data_path,args.rtr_name))
f.save_as_json("%s/%s.tf.json"%(args.data_path,args.rtr_name))
コード例 #7
0
    stage = args.view[0]
    i = 1
    for rule in f.rules:
        if stage == get_stage(rule):
            print i, ":", get_openflow_rule(rule, inv_mapf)
        i = i + 1
if args.rm:
    indices = args.rm[0].split(",")
    indices = [int(i) for i in indices]
    indices.sort(reverse=True)
    for index in indices:
        f.remove_rule(index - 1)

if args.add:
    positions = (args.add[0]).split(",")
    rules = (args.add[1]).split(":")
    if len(rules) != len(positions):
        sys.stderr.write(
            "Number of positions and number of rules should be the same")
    for i in range(len(positions)):
        position = int(positions[i]) - 1
        tokens = rules[i].split(";")
        rule = parse_new_rule_tokens(tokens, mapf_extended, args.rtr_name)
        if rule["mask"] == None:
            f.add_fwd_rule(rule, position)
        elif rule["mask"] != None:
            f.add_rewrite_rule(rule, position)

f.save_object_to_file("%s/%s.tf" % (args.data_path, args.rtr_name))
f.save_as_json("%s/%s.tf.json" % (args.data_path, args.rtr_name))
コード例 #8
0
def make_NTF(num_mbox):
    line_counter = 1
    num_stack = num_mbox + 1
    NTF = TF(format["length"])
    
    m_addr = [dotted_ip_to_int("10.1.1.1"),
              dotted_ip_to_int("10.1.2.2"),
              dotted_ip_to_int("10.1.3.3"),
              dotted_ip_to_int("10.1.4.4"),
              dotted_ip_to_int("10.1.5.5"),]
    m_subnet = [dotted_ip_to_int("10.1.1.0"),
              dotted_ip_to_int("10.1.2.0"),
              dotted_ip_to_int("10.1.3.0"),
              dotted_ip_to_int("10.1.4.0"),
              dotted_ip_to_int("10.1.5.0"),]
    
    sender_addr = dotted_ip_to_int("10.1.10.1")
    receiver_addr = dotted_ip_to_int("10.1.20.1")
    network_subnet = dotted_ip_to_int("10.1.0.0")
    
    # rules for R1
    for i in range(num_mbox):
        ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,m_addr[i],32)
        rule = TF.create_standard_rule([1,7], ip_match, [2], None, None, "sample.txt", [line_counter])
        NTF.add_fwd_rule(rule)
        line_counter += 1
        
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,receiver_addr,32)
    rule = TF.create_standard_rule([1,2], ip_match, [7], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,sender_addr,32)
    rule = TF.create_standard_rule([2,7], ip_match, [1], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1
    
    # Add rule for R2:
    all_ip_star_ingress_ports = []
    for i in range(num_mbox):
        ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,m_addr[i],32)
        rule = TF.create_standard_rule([3,4], ip_match, [14+4*i], None, None, "sample.txt", [line_counter])
        NTF.add_fwd_rule(rule)
        line_counter += 1
        all_ip_star_ingress_ports.append(14+4*i)
    
    for i in range(num_mbox):
        rule = TF.create_custom_rule(make_IP_str_match(all_ip_star_ingress_ports), 
                                     make_IP_str_transform(m_addr[i], 32, [all_ip_star_ingress_ports[i]]), 
                                     make_IP_str_inv_match([all_ip_star_ingress_ports[i]], m_addr[i], 32), 
                                     make_IP_str_inv_transform(all_ip_star_ingress_ports), 
                                     "sample.txt", [line_counter])
        NTF.add_custom_rule(rule)
        line_counter += 1
    rule = TF.create_custom_rule(make_IP_str_match(all_ip_star_ingress_ports), 
                                 make_IP_str_transform(sender_addr, 32, [4]), 
                                 make_IP_str_inv_match([4], sender_addr, 32), 
                                 make_IP_str_inv_transform(all_ip_star_ingress_ports), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
    rule = TF.create_custom_rule(make_IP_str_match(all_ip_star_ingress_ports), 
                                 make_IP_str_transform(receiver_addr, 32, [3]), 
                                 make_IP_str_inv_match([3], receiver_addr, 32), 
                                 make_IP_str_inv_transform(all_ip_star_ingress_ports), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
        
    
    # add rule for R3:
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,receiver_addr,32)
    rule = TF.create_standard_rule([5,6], ip_match, [8], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,sender_addr,32)
    rule = TF.create_standard_rule([5], ip_match, [6], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1    
    rule = TF.create_custom_rule(make_IP_str_match([8]), 
                                 make_IP_str_transform(receiver_addr, 32, [8]), 
                                 make_IP_str_inv_match([8], receiver_addr, 32), 
                                 make_IP_str_inv_transform([8]), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
    rule = TF.create_custom_rule(make_IP_str_match([8]), 
                                 make_IP_str_transform(sender_addr, 32, [6]), 
                                 make_IP_str_inv_match([6], sender_addr, 32), 
                                 make_IP_str_inv_transform([8]), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
    
    for i in range(num_mbox):
        rule = TF.create_custom_rule(make_IP_str_match([8]), 
                                     make_IP_str_transform(m_addr[i], 32, [5]), 
                                     make_IP_str_inv_match([5], m_addr[i], 32), 
                                     make_IP_str_inv_transform([8]), 
                                     "sample.txt", [line_counter])
        NTF.add_custom_rule(rule)
        line_counter += 1
        ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,m_addr[i],32)
        rule = TF.create_standard_rule([6], ip_match, [5], None, None, "sample.txt", [line_counter])
        NTF.add_fwd_rule(rule)
        line_counter += 1 
        
    
    # add rule for R4,R5,R8,R9,...
    for i in range(num_mbox):
        ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,m_subnet[i],24)
        rule = TF.create_standard_rule([15 + 4*i], ip_match, [16 + 4*i], None, None, "sample.txt", [line_counter])
        NTF.add_fwd_rule(rule)
        line_counter += 1 
        ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,network_subnet,18)
        rule = TF.create_standard_rule([16 + 4*i], ip_match, [15 + 4*i], None, None, "sample.txt", [line_counter])
        NTF.add_fwd_rule(rule)
        line_counter += 1 
        
    # add rule for R6
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,receiver_addr,32)
    rule = TF.create_standard_rule([9], ip_match, [10], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1 
    ip_match = make_byte_array_ip_star_hdr(None,[],[],0,0,network_subnet,16)
    rule = TF.create_standard_rule([10], ip_match, [9], None, None, "sample.txt", [line_counter])
    NTF.add_fwd_rule(rule)
    line_counter += 1 
    
    # add rule for R7
    rule = TF.create_custom_rule(make_IP_str_match([11]), 
                                 make_IP_str_transform(receiver_addr, 32, [12]), 
                                 make_IP_str_inv_match([12], receiver_addr, 32), 
                                 make_IP_str_inv_transform([11]), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
    rule = TF.create_custom_rule(make_IP_str_match([11]), 
                                 make_IP_str_transform(network_subnet, 21, [11]), 
                                 make_IP_str_inv_match([11], network_subnet, 21), 
                                 make_IP_str_inv_transform([11]), 
                                 "sample.txt", [line_counter])
    NTF.add_custom_rule(rule)
    line_counter += 1
    
    # rule for middle boxes:
    for i in range(num_mbox):
        rule = TF.create_custom_rule(make_mbox_match(m_addr[i], 32, 17+4*i), 
                                     make_mbox_tf(), 
                                     make_mbox_inv_match(m_addr[i], 32, 17+4*i), 
                                     make_mbox_tf(), 
                                     "sample.txt", [line_counter])
        NTF.add_custom_rule(rule)
        line_counter += 1
        
    return NTF