示例#1
0
 def python_check_connectivity(simulation, check_liveness_first=True):
     # Warning! depends on python Hassell -- may be really slow!
     import topology_loader.topology_loader as hsa_topo
     import headerspace.applications as hsa
     if check_liveness_first:
         simulation.controller_manager.check_controller_status()
         if simulation.controller_manager.all_controllers_down():
             return simulation.controller_manager.cids
     NTF = hsa_topo.generate_NTF(simulation.topology.live_switches)
     TTF = hsa_topo.generate_TTF(simulation.topology.live_links)
     paths = hsa.find_reachability(NTF, TTF,
                                   simulation.topology.access_links)
     # Paths is: in_port -> [p_node1, p_node2]
     # Where p_node is a hash:
     #  "hdr" -> foo
     #  "port" -> foo
     #  "visits" -> foo
     connected_pairs = set()
     for in_port, p_nodes in paths.iteritems():
         for p_node in p_nodes:
             connected_pairs.add((in_port, p_node["port"]))
     unconnected_pairs = InvariantChecker._get_unconnected_pairs(
         simulation, connected_pairs)
     violations = [str(pair) for pair in unconnected_pairs]
     violations = list(set(violations))
     return violations
示例#2
0
 def _python_get_connected_pairs(simulation):
   import topology_loader.topology_loader as hsa_topo
   import headerspace.applications as hsa
   NTF = hsa_topo.generate_NTF(simulation.topology.live_switches)
   TTF = hsa_topo.generate_TTF(simulation.topology.live_links)
   paths = hsa.find_reachability(NTF, TTF, simulation.topology.access_links)
   # Paths is: in_port -> [p_node1, p_node2]
   # Where p_node is a hash:
   #  "hdr" -> foo
   #  "port" -> foo
   #  "visits" -> foo
   connected_pairs = set()
   for in_port, p_nodes in paths.iteritems():
     for p_node in p_nodes:
       connected_pairs.add((in_port, p_node["port"]))
   return connected_pairs
示例#3
0
 def _python_get_connected_pairs(simulation):
     import topology_loader.topology_loader as hsa_topo
     import headerspace.applications as hsa
     NTF = hsa_topo.generate_NTF(simulation.topology.live_switches)
     TTF = hsa_topo.generate_TTF(simulation.topology.live_links)
     paths = hsa.find_reachability(NTF, TTF,
                                   simulation.topology.access_links)
     # Paths is: in_port -> [p_node1, p_node2]
     # Where p_node is a hash:
     #  "hdr" -> foo
     #  "port" -> foo
     #  "visits" -> foo
     connected_pairs = set()
     for in_port, p_nodes in paths.iteritems():
         for p_node in p_nodes:
             connected_pairs.add((in_port, p_node["port"]))
     return connected_pairs
 def python_check_connectivity(simulation, check_liveness_first=True):
   # Warning! depends on python Hassell -- may be really slow!
   import topology_loader.topology_loader as hsa_topo
   import headerspace.applications as hsa
   if check_liveness_first and simulation.controller_manager.all_controllers_down():
     return simulation.controller_manager.cids
   NTF = hsa_topo.generate_NTF(simulation.topology.live_switches)
   TTF = hsa_topo.generate_TTF(simulation.topology.live_links)
   paths = hsa.find_reachability(NTF, TTF, simulation.topology.access_links)
   # Paths is: in_port -> [p_node1, p_node2]
   # Where p_node is a hash:
   #  "hdr" -> foo
   #  "port" -> foo
   #  "visits" -> foo
   connected_pairs = set()
   for in_port, p_nodes in paths.iteritems():
     for p_node in p_nodes:
       connected_pairs.add((in_port, p_node["port"]))
   unconnected_pairs = InvariantChecker._get_unconnected_pairs(simulation, connected_pairs)
   violations = [ str(pair) for pair in unconnected_pairs ]
   violations = list(set(violations))
   return violations
示例#5
0
            "switch_id_multiplier":cisco_router.SWITCH_ID_MULTIPLIER,
            "port_type_multiplier":cisco_router.PORT_TYPE_MULTIPLIER,
            "out_port_type_const":cisco_router.OUTPUT_PORT_TYPE_CONST,
            "remove_duplicates":True,
            }

(ntf,ttf,name_to_id,id_to_name) = load_network(settings)

# create all-x packet as input headerspace.
all_x = wildcard_create_bit_repeat(ntf.length,0x3)
# uncomment to set some field
#set_header_field(cisco_router.HS_FORMAT(), all_x, "field", value, right_mask)
#set_header_field(cisco_router.HS_FORMAT(), all_x, "vlan", 92, 0)
test_pkt = headerspace(ntf.length)
test_pkt.add_hs(all_x)

#set some input/output ports
output_port_addition = cisco_router.PORT_TYPE_MULTIPLIER * \
cisco_router.OUTPUT_PORT_TYPE_CONST
#TODO: CHANGE THIS IF YOU WANT TO RUN IT FROM/TO DIFFERENT PORTS
src_port_id = name_to_id["ROUTER NAME"]["PORT NAME"]
dst_port_ids = [name_to_id["ROUTER NAME"]["PORT NAME"]+output_port_addition]

#start reachability test and print results
st = time()
paths = find_reachability(ntf, ttf, src_port_id, dst_port_ids, test_pkt)
en = time()
print_paths(paths, id_to_name)

print "Found ",len(paths)," paths in ",en-st," seconds."
示例#6
0
            "switch_id_multiplier":cisco_router.SWITCH_ID_MULTIPLIER,
            "port_type_multiplier":cisco_router.PORT_TYPE_MULTIPLIER,
            "out_port_type_const":cisco_router.OUTPUT_PORT_TYPE_CONST,
            "remove_duplicates":True,
            }

(ntf,ttf,name_to_id,id_to_name) = load_network(settings)

# create all-x packet as input headerspace.
all_x = wildcard_create_bit_repeat(ntf.length,0x3)
# uncomment to set some field
#set_header_field(cisco_router.HS_FORMAT(), all_x, "field", value, right_mask)
#set_header_field(cisco_router.HS_FORMAT(), all_x, "vlan", 92, 0)
test_pkt = headerspace(ntf.length)
test_pkt.add_hs(all_x)

#set some input/output ports
output_port_addition = cisco_router.PORT_TYPE_MULTIPLIER * \
cisco_router.OUTPUT_PORT_TYPE_CONST
#TODO: CHANGE THIS IF YOU WANT TO RUN IT FROM/TO DIFFERENT PORTS
src_port_id = name_to_id["ROUTER NAME"]["PORT NAME"]
dst_port_ids = [name_to_id["ROUTER NAME"]["PORT NAME"]+output_port_addition]

#start reachability test and print results
st = time()
paths = find_reachability(ntf, ttf, src_port_id, dst_port_ids, test_pkt)
en = time()
print_paths(paths, id_to_name)

print "Found ",len(paths)," paths in ",en-st," seconds."