def setUp(self): # Define namespace id and names self.ns_id1 = "ns_id1" self.ns_id2 = "ns_id2" self.ns_name1 = "ns_name1" self.ns_name2 = "ns_name2" # Add namespaces TopologyMap.add_namespace(self.ns_id1, self.ns_name1) TopologyMap.add_namespace(self.ns_id2, self.ns_name2) # Define interface id and names self.int_id1 = "int_id1" self.int_id2 = "int_id2" self.int_name1 = "int_name1" self.int_name2 = "int_name2" # Add interfaces TopologyMap.add_interface(self.ns_id1, self.int_id1, self.int_name1) TopologyMap.add_interface(self.ns_id1, self.int_id2, self.int_name2)
def __init__(self, name): """ Create a node with given `name`. An unique `id` is assigned to this node which is used by `engine` module to create the network namespace. This ensures that there is no naming conflict between any two nodes. Parameters ---------- name: str The name of the node to be created """ if name == "": raise ValueError("Node name can't be an empty string") if config.get_value("assign_random_names") is False and len(name) > 3: # We chose 3 because: 'ifb-ns1-ns2-20' is a potential IFB interface name # and it's already 14 character long. Note that here node names # are 'ns1' and 'ns2'. The `ip` utility won't accept interface names # longer than 15 characters logger.warning( "%s is longer than 3 characters. It's safer to use " "node names with atmost 3 characters with the current config.", name, ) self._name = name self._id = IdGen.get_id(name) self._interfaces = [] # mpls max platform label kernel parameter self._mpls_max_label = 0 # Global variable disables when any new node is created # to ensure DAD check (if applicable) g_var.IS_DAD_CHECKED = False engine.create_ns(self.id) engine.set_interface_mode(self.id, "lo", "up") TopologyMap.add_namespace(self.id, self.name) TopologyMap.add_host(self)
def test_add_same_entity_again(self): with self.assertRaises(ValueError): TopologyMap.add_namespace(self.ns_id1, self.ns_name1) with self.assertRaises(ValueError): TopologyMap.add_interface(self.ns_id1, self.int_id1, self.int_name1)