def test_demand_behavior(self): model = FlexModel.load_model_file( 'test/parallel_link_model_test_topology.csv') model.update_simulation() dmd_a_f = model.get_demand_object('A', 'F', 'dmd_a_f_1') # int_a_b = model.get_interface_object('A-to-B', 'A') # int_b_d = model.get_interface_object('B-to-D', 'B') # int_b_g = model.get_interface_object('B-to-G', 'B') # int_g_d = model.get_interface_object('G-to-D', 'G') # int_d_f = model.get_interface_object('D-to-F', 'D') # int_a_c = model.get_interface_object('A-to-C', 'A') # int_c_d = model.get_interface_object('C-to-D', 'C') # int_a_d = model.get_interface_object('A-to-D', 'A') # Demand routes initially self.assertNotEqual(dmd_a_f.path, 'Unrouted') # Demand should not route if source node is down model.fail_node('A') model.update_simulation() self.assertEqual(dmd_a_f.path, 'Unrouted') # Demand should route when source node unfails model.unfail_node('A') model.update_simulation() self.assertNotEqual(dmd_a_f.path, 'Unrouted') # Demand should not route when dest node fails model.fail_node('F') model.update_simulation() self.assertEqual(dmd_a_f.path, 'Unrouted') # Demand should route when dest node unfails model.unfail_node('F') model.update_simulation() self.assertNotEqual(dmd_a_f.path, 'Unrouted')
def test_add_orphan_interface(self): """ Tests adding an unpaired Interface to the model's interface_objects set """ model = FlexModel.load_model_file( 'test/parallel_link_model_test_topology.csv') model.update_simulation() node_a = model.get_node_object('A') node_b = model.get_node_object('B') orphan_int = Interface('A-to-B', 100, 100, node_a, node_b, circuit_id=80) model.interface_objects.add(orphan_int) err_msg = "No matching Interface Object found" with self.assertRaises(ModelException) as context: model.update_simulation() self.assertIn(err_msg, context.exception.args[0])
def test_add_ckt_duplicate_circuit_id(self): """ Add a circuit to model, specifying a circuit_id value that already exists """ model = FlexModel.load_model_file( 'test/parallel_link_model_test_topology.csv') model.update_simulation() node_a = model.get_node_object('A') node_x = model.get_node_object('X') err_msg = 'circuit_id value 1 is already exists in model' with self.assertRaises(ModelException) as context: model.add_circuit(node_a, node_x, 'A-to-X_2', 'X-to-A_2', 10, 10, 1000, circuit_id='1') self.assertIn(err_msg, context.exception.args[0])
def test_ckt_add(self): model = FlexModel.load_model_file( 'test/parallel_link_model_test_topology.csv') model.update_simulation() node_zz = Node('ZZ') model.add_node(node_zz) model.update_simulation() node_a = model.get_node_object('A') model.add_circuit(node_a, node_zz, 'A-to-ZZ', 'ZZ-to-A', 20, 20, 1000, circuit_id=90) model.update_simulation() ckt = model.get_circuit_object_from_interface('ZZ-to-A', 'ZZ') self.assertTrue(isinstance(ckt, Circuit))
def test_node_in_failed_srlg_unfails_when_removed(self): model = FlexModel.load_model_file( "test/parallel_link_model_test_topology.csv") node_a = model.get_node_object("A") model.update_simulation() node_a.add_to_srlg("new_srlg", model, create_if_not_present=True) new_srlg = model.get_srlg_object("new_srlg") self.assertFalse(node_a.failed) self.assertTrue(node_a in new_srlg.node_objects) model.fail_srlg("new_srlg") self.assertTrue(new_srlg.failed) model.update_simulation() self.assertTrue(node_a.failed) node_a.remove_from_srlg("new_srlg", model) model.update_simulation() self.assertNotIn(node_a, new_srlg.node_objects) self.assertFalse(node_a.failed)
def test_get_non_failed_nodes(self): model = FlexModel.load_model_file( 'test/parallel_link_model_test_topology.csv') model.update_simulation() model.fail_node('A') model.fail_node('G') model.update_simulation() node_b = model.get_node_object('B') node_c = model.get_node_object('C') node_d = model.get_node_object('D') node_e = model.get_node_object('E') node_f = model.get_node_object('F') node_x = model.get_node_object('X') node_h = model.get_node_object('H') node_y = model.get_node_object('Y') unfailed_node_list = [ node_b, node_c, node_d, node_e, node_f, node_x, node_h, node_y ] self.assertEqual(set(model.get_non_failed_node_objects()), set(unfailed_node_list))
import sys sys.path.append("../") from pprint import pprint from pyNTM import FlexModel from pyNTM.weathermap import WeatherMap model = FlexModel.load_model_file( "igp_shortcuts_model_mult_lsps_in_path_parallel_links_2.csv") model.update_simulation() sp_a_f = model.get_shortest_path("A", "F") print("shortest path from A to F is:") pprint(sp_a_f) print() dmd_a_f = model.get_demand_object("A", "F", "dmd_a_f_1") print("dmd_a_f_1 path is:") pprint(dmd_a_f.path) wm = WeatherMap(model) wm.spacing_factor = 5 wm.create_weathermap()
def test_failed_node_interfaces(self): model = FlexModel.load_model_file('test/parallel_link_model_test_topology.csv') model.update_simulation() model.fail_node('A') model.update_simulation() self.assertEqual(len(model.get_failed_interface_objects()), 10)
def test_lsp_demand_path_detail_flex_model_lsp_and_igp_routed(self): model = FlexModel.load_model_file( "test/igp_shortcuts_model_mult_lsps_in_path.csv") model.update_simulation() dmd_a_f_1 = model.get_demand_object("A", "F", "dmd_a_f_1") int_a_g = model.get_interface_object("A-G", "A") int_g_f = model.get_interface_object("G-F", "G") int_a_b = model.get_interface_object("A-B", "A") lsp_b_d_1 = model.get_rsvp_lsp("B", "D", "lsp_b_d_1") lsp_b_d_2 = model.get_rsvp_lsp("B", "D", "lsp_b_d_2") lsp_d_f_1 = model.get_rsvp_lsp("D", "F", "lsp_d_f_1") # dmd_a_f_1.path_detail should look something like this: # {'path_0': {'items': [ # Interface(name='A-G', cost=25, capacity=100, node_object=Node('A'), remote_node_object=Node('G'), # circuit_id='6'), # Interface(name='G-F', cost=25, capacity=100, node_object=Node('G'), remote_node_object=Node('F'), # circuit_id='7')], # 'path_traffic': 5.0, # 'splits': {Interface(name='A-G', cost=25, capacity=100, node_object=Node('A'), # remote_node_object=Node('G'), circuit_id='6'): 2, # Interface(name='G-F', cost=25, capacity=100, node_object=Node('G'), # remote_node_object=Node('F'), circuit_id='7'): 2}}, # 'path_1': {'items': [ # Interface(name='A-B', cost=10, capacity=100, node_object=Node('A'), remote_node_object=Node('B'), # circuit_id='1'), # RSVP_LSP(source=B, dest=D, lsp_name='lsp_b_d_2'), # RSVP_LSP(source=D, dest=F, lsp_name='lsp_d_f_1')], # 'path_traffic': 2.5, # 'splits': {Interface(name='A-B', cost=10, capacity=100, node_object=Node('A'), # remote_node_object=Node('B'), circuit_id='1'): 2, # RSVP_LSP(source=D, dest=F, lsp_name='lsp_d_f_1'): 4, # RSVP_LSP(source=B, dest=D, lsp_name='lsp_b_d_2'): 4}}, # 'path_2': {'items': [ # Interface(name='A-B', cost=10, capacity=100, node_object=Node('A'), remote_node_object=Node('B'), # circuit_id='1'), # RSVP_LSP(source=B, dest=D, lsp_name='lsp_b_d_1'), # RSVP_LSP(source=D, dest=F, lsp_name='lsp_d_f_1')], # 'path_traffic': 2.5, # 'splits': {Interface(name='A-B', cost=10, capacity=100, node_object=Node('A'), # remote_node_object=Node('B'), circuit_id='1'): 2, # RSVP_LSP(source=B, dest=D, lsp_name='lsp_b_d_1'): 4, # RSVP_LSP(source=D, dest=F, lsp_name='lsp_d_f_1'): 4}}} dmd_pd = dmd_a_f_1.path_detail # Confirm 3 paths exist self.assertEqual(len(dmd_pd), 3) list_of_paths_items = [ dmd_pd["path_0"]["items"], dmd_pd["path_1"]["items"], dmd_pd["path_2"]["items"], ] # Confirm the path with the 2 interfaces self.assertIn([int_a_g, int_g_f], list_of_paths_items) # Confirm the 2 paths that differ only be lsp_b_d_1/lsp_b_d_2 self.assertIn([int_a_b, lsp_b_d_1, lsp_d_f_1], list_of_paths_items) self.assertIn([int_a_b, lsp_b_d_2, lsp_d_f_1], list_of_paths_items) # Confirm the path A-G-F Interfaces only has 5 units of traffic five_traff_path = [ path for path in dmd_a_f_1.path_detail if dmd_a_f_1.path_detail[path]["items"] == [int_a_g, int_g_f] ][0] self.assertEqual(dmd_pd[five_traff_path]["path_traffic"], 5.0) # Confirm the path [A-B, lsp_b_d_1, lsp_d_f_1] and [A-B, lsp_b_d_2, lsp_d_f_1] have 2.5 traffic units each lsp_path_1 = [ path for path in dmd_a_f_1.path_detail if dmd_a_f_1.path_detail[path]["items"] == [int_a_b, lsp_b_d_1, lsp_d_f_1] ][0] lsp_path_2 = [ path for path in dmd_a_f_1.path_detail if dmd_a_f_1.path_detail[path]["items"] == [int_a_b, lsp_b_d_2, lsp_d_f_1] ][0] self.assertEqual(dmd_pd[lsp_path_1]["path_traffic"], 2.5) self.assertEqual(dmd_pd[lsp_path_2]["path_traffic"], 2.5) # Confirm the split values of each path self.assertIn(2, set(dmd_pd[five_traff_path]["splits"].values())) self.assertEqual(1, len(set(dmd_pd[five_traff_path]["splits"].values()))) self.assertEqual({2, 4}, set(dmd_pd[lsp_path_1]["splits"].values())) self.assertEqual({2, 4}, set(dmd_pd[lsp_path_2]["splits"].values()))
import sys sys.path.append('../') from pprint import pprint from pyNTM import FlexModel # Make the Parallel_Link_Model model = FlexModel.load_model_file('igp_shortcuts_model_mult_lsps_in_path.csv') model.update_simulation() dmd_a_f_1 = model.get_demand_object('A', 'F', 'dmd_a_f_1') dmd_d_f_1 = model.get_demand_object('D', 'F', 'dmd_d_f_1') node_a = model.get_node_object('A') lsp_b_d_1 = model.get_rsvp_lsp('B', 'D', 'lsp_b_d_1') lsp_b_d_2 = model.get_rsvp_lsp('B', 'D', 'lsp_b_d_2') print("Interfaces with traffic") for interface in model.interface_objects: if interface.traffic > 0: print([interface, interface.traffic, interface.utilization]) print() # for dmd in model.demand_objects: # pprint([dmd, dmd.path_detail]) print("LSPs and their traffic") for lsp in model.rsvp_lsp_objects: print([lsp, lsp.traffic_on_lsp(model)]) print() lsp_d_f = model.get_rsvp_lsp('D', 'F', 'lsp_d_f_1')
import sys sys.path.append('../') from pprint import pprint from pyNTM import FlexModel from pyNTM.weathermap import WeatherMap # Make the Parallel_Link_Model model = FlexModel.load_model_file('model_test_topology_multidigraph.csv') model.update_simulation() print() # Get shorteset path from Node A to Node D a_d = model.get_shortest_path('A', 'D') # Print the shortest path(s) print("There are {} shortest path(s) from Node A to Node D.".format(len(a_d['path']))) print("The shortest path(s) from Node A to Node D:") for path in a_d['path']: pprint(path) print() # Find the shortest path(s) from A to D with 75 units of reservable_bandwidth a_d_75 = model.get_shortest_path('A', 'D', needed_bw=75) # Print the path(s) print("There are {} shortest path(s) from Node A to Node D with at least 75 units of" "reserable bandwidth.".format(len(a_d_75['path']))) print("The shortest path(s) from Node A to Node D with 75 units of reservable bandwidth:") for path in a_d_75['path']:
import sys sys.path.append("../") from pprint import pprint from pyNTM import FlexModel from pyNTM.weathermap import WeatherMap # Make the Parallel_Link_Model model = FlexModel.load_model_file("model_test_topology_flexmodel.csv") model.update_simulation() print() # Get shorteset path from Node A to Node D a_d = model.get_shortest_path("A", "D") # Print the shortest path(s) print("There are {} shortest path(s) from Node A to Node D.".format( len(a_d["path"]))) print("The shortest path(s) from Node A to Node D:") for path in a_d["path"]: pprint(path) print() # Find the shortest path(s) from A to D with 75 units of reservable_bandwidth a_d_75 = model.get_shortest_path("A", "D", needed_bw=75) # Print the path(s) print( "There are {} shortest path(s) from Node A to Node D with at least 75 units of"
def test_implied_node(self): model = FlexModel.load_model_file('test/parallel_link_model_test_topology.csv') node_x = model.get_node_object('X') self.assertTrue(node_x in model.node_objects)
def test_changed_metric(self): model = FlexModel.load_model_file( "test/igp_shortcuts_model_mult_lsps_in_path.csv") # Get all the interface objects int_a_b = model.get_interface_object("A-B", "A") int_b_c = model.get_interface_object("B-C", "B") int_c_d = model.get_interface_object("C-D", "C") int_d_e = model.get_interface_object("D-E", "D") int_e_f = model.get_interface_object("E-F", "E") int_a_g = model.get_interface_object("A-G", "A") int_g_f = model.get_interface_object("G-F", "G") # Get all LSP objects lsp_b_d_1 = model.get_rsvp_lsp("B", "D", "lsp_b_d_1") lsp_b_d_2 = model.get_rsvp_lsp("B", "D", "lsp_b_d_2") lsp_c_e_1 = model.get_rsvp_lsp("C", "E", "lsp_c_e_1") lsp_d_f_1 = model.get_rsvp_lsp("D", "F", "lsp_d_f_1") # Get demand objects dmd_a_f_1 = model.get_demand_object("A", "F", "dmd_a_f_1") dmd_d_f_1 = model.get_demand_object("D", "F", "dmd_d_f_1") # Give lsp a lower than default metric lsp_b_d_1.manual_metric = 15 model.update_simulation() dmd_path_1 = [int_a_b, lsp_b_d_1, lsp_d_f_1] # Confirm demand path self.assertIn(dmd_path_1, dmd_a_f_1.path) # Verify traffic on LSPs self.assertEqual(lsp_b_d_1.traffic_on_lsp(model), 10) self.assertEqual(lsp_b_d_2.traffic_on_lsp(model), 0) self.assertEqual(lsp_c_e_1.traffic_on_lsp(model), 0) self.assertEqual(lsp_d_f_1.traffic_on_lsp(model), 18.0) # Verify demand paths self.assertNotIn([int_a_g, int_g_f], dmd_a_f_1.path) self.assertIn([int_a_b, lsp_b_d_1, lsp_d_f_1], dmd_a_f_1.path) self.assertNotIn(lsp_b_d_2, dmd_a_f_1.path) self.assertEqual(dmd_d_f_1.path, [[lsp_d_f_1]]) # Verify interface traffic self.assertEqual(int_a_b.traffic, 10.0) self.assertEqual(int_b_c.traffic, 10.0) self.assertEqual(int_c_d.traffic, 10.0) self.assertEqual(int_d_e.traffic, 18.0) self.assertEqual(int_e_f.traffic, 18.0) self.assertEqual(int_a_g.traffic, 0.0) self.assertEqual(int_g_f.traffic, 0.0) # Verify LSPs on interfaces self.assertIn(lsp_b_d_1, int_b_c.lsps(model)) self.assertIn(lsp_b_d_2, int_b_c.lsps(model)) self.assertIn(lsp_b_d_1, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_c_e_1, int_c_d.lsps(model)) # Give lsp_b_d_1 a higher than default metric lsp_b_d_1.manual_metric = 25 model.update_simulation() dmd_path_2_1 = [int_a_g, int_g_f] dmd_path_2_2 = [int_a_b, lsp_b_d_2, lsp_d_f_1] # Confirm demand path self.assertIn(dmd_path_2_1, dmd_a_f_1.path) self.assertIn(dmd_path_2_2, dmd_a_f_1.path) # Verify traffic on LSPs self.assertEqual(lsp_b_d_1.traffic_on_lsp(model), 0) self.assertEqual(lsp_b_d_2.traffic_on_lsp(model), 5) self.assertEqual(lsp_c_e_1.traffic_on_lsp(model), 0) self.assertEqual(lsp_d_f_1.traffic_on_lsp(model), 13.0) # Verify demand paths self.assertIn([int_a_g, int_g_f], dmd_a_f_1.path) self.assertNotIn(lsp_b_d_1, dmd_a_f_1.path) self.assertIn([int_a_b, lsp_b_d_2, lsp_d_f_1], dmd_a_f_1.path) self.assertEqual(dmd_d_f_1.path, [[lsp_d_f_1]]) # Verify interface traffic self.assertEqual(int_a_b.traffic, 5.0) self.assertEqual(int_b_c.traffic, 5.0) self.assertEqual(int_c_d.traffic, 5.0) self.assertEqual(int_d_e.traffic, 13.0) self.assertEqual(int_e_f.traffic, 13.0) self.assertEqual(int_a_g.traffic, 5.0) self.assertEqual(int_g_f.traffic, 5.0) # Verify LSPs on interfaces self.assertIn(lsp_b_d_1, int_b_c.lsps(model)) self.assertIn(lsp_b_d_2, int_b_c.lsps(model)) self.assertIn(lsp_b_d_1, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_c_e_1, int_c_d.lsps(model))
def test_interface_fields_missing_model_file_load(self): err_msg = 'node_name, remote_node_name, name, cost, capacity, circuit_id must be defined for line' with self.assertRaises(ModelException) as context: FlexModel.load_model_file('test/interface_field_info_missing_routing_topology_multidigraph.csv') self.assertTrue(err_msg in err_msg in context.exception.args[0])
def test_repr(self): model = FlexModel.load_model_file( 'test/parallel_link_model_test_topology.csv') new_srlg = SRLG('new_srlg', model) self.assertEqual(new_srlg.__repr__(), 'SRLG(Name: new_srlg)')
def test_fail_node(self): model = FlexModel.load_model_file('test/parallel_link_model_test_topology.csv') model.update_simulation() model.fail_node('A') model.update_simulation() self.assertTrue(model.get_node_object('A').failed)
def test_get_unfailed_ints_2(self): model = FlexModel.load_model_file('test/parallel_link_model_test_topology.csv') model.update_simulation() model.fail_interface('A-to-B', 'A') model.update_simulation() self.assertEqual(len(model.get_unfailed_interface_objects()), 38)
def test_traffic_on_shortcut_lsps(self): """ Verify Interface and LSP traffic when IGP shortcuts enabled in baseline model. """ # The demands should take LSPs starting on the first # node that has shortcuts and should take the LSP that # leads it closest to the demand destination model = FlexModel.load_model_file( 'test/igp_shortcuts_model_mult_lsps_in_path.csv') model.update_simulation() # Get all the interface objects int_a_b = model.get_interface_object('A-B', 'A') int_b_c = model.get_interface_object('B-C', 'B') int_c_d = model.get_interface_object('C-D', 'C') int_d_e = model.get_interface_object('D-E', 'D') int_e_f = model.get_interface_object('E-F', 'E') int_a_g = model.get_interface_object('A-G', 'A') int_g_f = model.get_interface_object('G-F', 'G') # Get all LSP objects lsp_b_d_1 = model.get_rsvp_lsp('B', 'D', 'lsp_b_d_1') lsp_b_d_2 = model.get_rsvp_lsp('B', 'D', 'lsp_b_d_2') lsp_c_e_1 = model.get_rsvp_lsp('C', 'E', 'lsp_c_e_1') lsp_d_f_1 = model.get_rsvp_lsp('D', 'F', 'lsp_d_f_1') # Get demand objects dmd_a_f_1 = model.get_demand_object('A', 'F', 'dmd_a_f_1') dmd_d_f_1 = model.get_demand_object('D', 'F', 'dmd_d_f_1') # Verify traffic on LSPs self.assertEqual(lsp_b_d_1.traffic_on_lsp(model), 2.5) self.assertEqual(lsp_b_d_2.traffic_on_lsp(model), 2.5) self.assertEqual(lsp_c_e_1.traffic_on_lsp(model), 0) self.assertEqual(lsp_d_f_1.traffic_on_lsp(model), 13.0) # Verify demand paths self.assertIn([int_a_g, int_g_f], dmd_a_f_1.path) self.assertIn([int_a_b, lsp_b_d_1, lsp_d_f_1], dmd_a_f_1.path) self.assertIn([int_a_b, lsp_b_d_2, lsp_d_f_1], dmd_a_f_1.path) self.assertEqual(dmd_d_f_1.path, [[lsp_d_f_1]]) # Verify interface traffic self.assertEqual(int_a_b.traffic, 5.0) self.assertEqual(int_b_c.traffic, 5.0) self.assertEqual(int_c_d.traffic, 5.0) self.assertEqual(int_d_e.traffic, 13.0) self.assertEqual(int_e_f.traffic, 13.0) self.assertEqual(int_a_g.traffic, 5.0) self.assertEqual(int_g_f.traffic, 5.0) # Verify LSPs on interfaces self.assertIn(lsp_b_d_1, int_b_c.lsps(model)) self.assertIn(lsp_b_d_2, int_b_c.lsps(model)) self.assertIn(lsp_b_d_1, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_c_e_1, int_c_d.lsps(model))
def test_repr(self): model = FlexModel.load_model_file( "test/parallel_link_model_test_topology.csv") new_srlg = SRLG("new_srlg", model) self.assertEqual(new_srlg.__repr__(), "SRLG(Name: new_srlg)")
def test_ckt_mismatch_int_capacity_file_load(self): err_msg = 'circuits_with_mismatched_interface_capacity' model = FlexModel.load_model_file('test/mismatched_ckt_int_capacity_topology_parallel_links.csv') with self.assertRaises(ModelException) as context: model.update_simulation() self.assertTrue(err_msg in context.exception.args[0][1][0].keys())
def setUpClass(self): self.model = FlexModel.load_model_file('test/test_rsvp_3rd_lsp_2_paths_parallel_links.csv') self.lsp_a_e_1 = self.model.get_rsvp_lsp('A', 'E', 'lsp_a_e_1') self.lsp_a_e_2 = self.model.get_rsvp_lsp('A', 'E', 'lsp_a_e_2') self.lsp_a_e_3 = self.model.get_rsvp_lsp('A', 'E', 'lsp_a_e_3') self.model.update_simulation()
import sys sys.path.append("../") from pyNTM import FlexModel model = FlexModel.load_model_file("flex_model_parallel_source_dest_lsps.csv") lsp_b_d_1 = model.get_rsvp_lsp("B", "D", "lsp_b_d_1") # lower metric lsp_b_d_3 = model.get_rsvp_lsp("B", "D", "lsp_b_d_3") # lower metric lsp_b_d_2 = model.get_rsvp_lsp("B", "D", "lsp_b_d_2") # default metric (higher) dmd_a_d_1 = model.get_demand_object("A", "D", "dmd_a_d_1") dmd_b_d_1 = model.get_demand_object("B", "D", "dmd_b_d_1") print("traffic on lsp_b_d_1 = {}".format(lsp_b_d_1.traffic_on_lsp(model))) print("traffic on lsp_b_d_2 = {}".format(lsp_b_d_2.traffic_on_lsp(model))) print("traffic on lsp_b_d_3 = {}".format(lsp_b_d_3.traffic_on_lsp(model)))
def test_traffic_on_shortcut_lsps(self): """ Verify Interface and LSP traffic when IGP shortcuts enabled in baseline model. """ # The demands should take LSPs starting on the first # node that has shortcuts and should take the LSP that # leads it closest to the demand destination model = FlexModel.load_model_file( "test/igp_shortcuts_model_mult_lsps_in_path.csv") model.update_simulation() # Get all the interface objects int_a_b = model.get_interface_object("A-B", "A") int_b_c = model.get_interface_object("B-C", "B") int_c_d = model.get_interface_object("C-D", "C") int_d_e = model.get_interface_object("D-E", "D") int_e_f = model.get_interface_object("E-F", "E") int_a_g = model.get_interface_object("A-G", "A") int_g_f = model.get_interface_object("G-F", "G") # Get all LSP objects lsp_b_d_1 = model.get_rsvp_lsp("B", "D", "lsp_b_d_1") lsp_b_d_2 = model.get_rsvp_lsp("B", "D", "lsp_b_d_2") lsp_c_e_1 = model.get_rsvp_lsp("C", "E", "lsp_c_e_1") lsp_d_f_1 = model.get_rsvp_lsp("D", "F", "lsp_d_f_1") # Get demand objects dmd_a_f_1 = model.get_demand_object("A", "F", "dmd_a_f_1") dmd_d_f_1 = model.get_demand_object("D", "F", "dmd_d_f_1") # Verify traffic on LSPs self.assertEqual(lsp_b_d_1.traffic_on_lsp(model), 2.5) self.assertEqual(lsp_b_d_2.traffic_on_lsp(model), 2.5) self.assertEqual(lsp_c_e_1.traffic_on_lsp(model), 0) self.assertEqual(lsp_d_f_1.traffic_on_lsp(model), 13.0) # Verify demand paths self.assertIn([int_a_g, int_g_f], dmd_a_f_1.path) self.assertIn([int_a_b, lsp_b_d_1, lsp_d_f_1], dmd_a_f_1.path) self.assertIn([int_a_b, lsp_b_d_2, lsp_d_f_1], dmd_a_f_1.path) self.assertEqual(dmd_d_f_1.path, [[lsp_d_f_1]]) # Verify interface traffic self.assertEqual(int_a_b.traffic, 5.0) self.assertEqual(int_b_c.traffic, 5.0) self.assertEqual(int_c_d.traffic, 5.0) self.assertEqual(int_d_e.traffic, 13.0) self.assertEqual(int_e_f.traffic, 13.0) self.assertEqual(int_a_g.traffic, 5.0) self.assertEqual(int_g_f.traffic, 5.0) # Verify LSPs on interfaces self.assertIn(lsp_b_d_1, int_b_c.lsps(model)) self.assertIn(lsp_b_d_2, int_b_c.lsps(model)) self.assertIn(lsp_b_d_1, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_c_e_1, int_c_d.lsps(model))
def test_changed_metric(self): model = FlexModel.load_model_file( 'test/igp_shortcuts_model_mult_lsps_in_path.csv') # Get all the interface objects int_a_b = model.get_interface_object('A-B', 'A') int_b_c = model.get_interface_object('B-C', 'B') int_c_d = model.get_interface_object('C-D', 'C') int_d_e = model.get_interface_object('D-E', 'D') int_e_f = model.get_interface_object('E-F', 'E') int_a_g = model.get_interface_object('A-G', 'A') int_g_f = model.get_interface_object('G-F', 'G') # Get all LSP objects lsp_b_d_1 = model.get_rsvp_lsp('B', 'D', 'lsp_b_d_1') lsp_b_d_2 = model.get_rsvp_lsp('B', 'D', 'lsp_b_d_2') lsp_c_e_1 = model.get_rsvp_lsp('C', 'E', 'lsp_c_e_1') lsp_d_f_1 = model.get_rsvp_lsp('D', 'F', 'lsp_d_f_1') # Get demand objects dmd_a_f_1 = model.get_demand_object('A', 'F', 'dmd_a_f_1') dmd_d_f_1 = model.get_demand_object('D', 'F', 'dmd_d_f_1') # Give lsp a lower than default metric lsp_b_d_1.manual_metric = 15 model.update_simulation() dmd_path_1 = [int_a_b, lsp_b_d_1, lsp_d_f_1] # Confirm demand path self.assertIn(dmd_path_1, dmd_a_f_1.path) # Verify traffic on LSPs self.assertEqual(lsp_b_d_1.traffic_on_lsp(model), 10) self.assertEqual(lsp_b_d_2.traffic_on_lsp(model), 0) self.assertEqual(lsp_c_e_1.traffic_on_lsp(model), 0) self.assertEqual(lsp_d_f_1.traffic_on_lsp(model), 18.0) # Verify demand paths self.assertNotIn([int_a_g, int_g_f], dmd_a_f_1.path) self.assertIn([int_a_b, lsp_b_d_1, lsp_d_f_1], dmd_a_f_1.path) self.assertNotIn(lsp_b_d_2, dmd_a_f_1.path) self.assertEqual(dmd_d_f_1.path, [[lsp_d_f_1]]) # Verify interface traffic self.assertEqual(int_a_b.traffic, 10.0) self.assertEqual(int_b_c.traffic, 10.0) self.assertEqual(int_c_d.traffic, 10.0) self.assertEqual(int_d_e.traffic, 18.0) self.assertEqual(int_e_f.traffic, 18.0) self.assertEqual(int_a_g.traffic, 0.0) self.assertEqual(int_g_f.traffic, 0.0) # Verify LSPs on interfaces self.assertIn(lsp_b_d_1, int_b_c.lsps(model)) self.assertIn(lsp_b_d_2, int_b_c.lsps(model)) self.assertIn(lsp_b_d_1, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_c_e_1, int_c_d.lsps(model)) # Give lsp_b_d_1 a higher than default metric lsp_b_d_1.manual_metric = 25 model.update_simulation() dmd_path_2_1 = [int_a_g, int_g_f] dmd_path_2_2 = [int_a_b, lsp_b_d_2, lsp_d_f_1] # Confirm demand path self.assertIn(dmd_path_2_1, dmd_a_f_1.path) self.assertIn(dmd_path_2_2, dmd_a_f_1.path) # Verify traffic on LSPs self.assertEqual(lsp_b_d_1.traffic_on_lsp(model), 0) self.assertEqual(lsp_b_d_2.traffic_on_lsp(model), 5) self.assertEqual(lsp_c_e_1.traffic_on_lsp(model), 0) self.assertEqual(lsp_d_f_1.traffic_on_lsp(model), 13.0) # Verify demand paths self.assertIn([int_a_g, int_g_f], dmd_a_f_1.path) self.assertNotIn(lsp_b_d_1, dmd_a_f_1.path) self.assertIn([int_a_b, lsp_b_d_2, lsp_d_f_1], dmd_a_f_1.path) self.assertEqual(dmd_d_f_1.path, [[lsp_d_f_1]]) # Verify interface traffic self.assertEqual(int_a_b.traffic, 5.0) self.assertEqual(int_b_c.traffic, 5.0) self.assertEqual(int_c_d.traffic, 5.0) self.assertEqual(int_d_e.traffic, 13.0) self.assertEqual(int_e_f.traffic, 13.0) self.assertEqual(int_a_g.traffic, 5.0) self.assertEqual(int_g_f.traffic, 5.0) # Verify LSPs on interfaces self.assertIn(lsp_b_d_1, int_b_c.lsps(model)) self.assertIn(lsp_b_d_2, int_b_c.lsps(model)) self.assertIn(lsp_b_d_1, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_b_d_2, int_c_d.lsps(model)) self.assertIn(lsp_c_e_1, int_c_d.lsps(model))