def __init__(self, data, controller): self.id = utils.generate_id() self.name = data["name"] if "openflow" in data: self.version = str(data["openflow"]["version"]) else: self.version = None if "mgmt_ips" in data: self.mgmt_ips = data["mgmt_ips"] else: self.mgmt_ips = None self.controller = controller self.status = "initialized" if "datapathid" in data: self.datapathid = int(data["datapathid"]) else: self.datapathid = int(self.id) # Insert the switch details in to DB self.docid = utils.switch_t.insert({ 'id': self.id, 'name': self.name, 'ofversion': self.version, 'controller': self.controller, 'datapathid': self.datapathid, 'status': self.status })
def __init__(self, data): self.id = utils.generate_id() self.name = data["name"] self.img = data["image"] self.status = "initialized" self.interfaces = data["interfaces"] # DB Updation self.docid = utils.host_t.insert({'id': self.id, 'name': self.name, 'img': self.img, 'interfaces': self.interfaces, 'status': self.status})
def __init__(self, data): self.id = utils.generate_id() self.name = data["name"] self.img = data["image"] self.status = "initialized" self.interfaces = data["interfaces"] self.mgmtif = False if "mgmt-if" in data: self.mgmtif = data["mgmt-if"] # DB Updation self.docid = utils.server_t.insert({'id': self.id, 'name': self.name, 'img': self.img, 'interfaces': self.interfaces, 'status': self.status})
def create(self): for router in self.routers: log.debug("Creating RouterLink" + str(router)) r = utils.get_router_data(router['name']) log.debug(r) # get IP from the router data r for the interface ip, mac = self.__getip(r['interfaces'], router["interface"]) log.debug(ip) log.debug(mac) # create a link node to switch ovs.create_link(self.switch, router["interface"], router['name'], ip, mac) # get the tap interface name tapif = ovs.get_port_name(router["name"], router["interface"]) # apply the Qos to the interface if "qos" in router: qos = self.getqos(router["qos"]) tc.config_qos(tapif, qos) sourceid = r["id"] # link -target node id s = utils.get_switch_data(self.switch) targetid = s["id"] # get the tap interface name tapif = ovs.get_port_name(router["name"], router["interface"]) # store the link endpoints in array (for UI drawing) self.links.append({ "source": sourceid, "target": targetid, "source-name": router["name"], "target-name": self.switch }) # update in DB self.docid = utils.link_t.insert({ 'id': utils.generate_id(), 'source': router["name"], 'target': self.switch, 'source-id': sourceid, 'target-id': targetid, 'if1': router["interface"], 'if2': tapif, 'qos': None, })
def create(self): for node in self.nodes: # print node node_interface = "eth1" qos = None #mac = None #if "mac" in node: # mac = node["mac"] #ip = self.network.getip() n = utils.get_node_data(node["name"]) # create a link node to switch ovs.create_link(self.switch, node_interface, node["name"], n['ip'], n['mac']) # get the tap interface name tapif = ovs.get_port_name(node["name"], node_interface) # link - source node id # sourceid = utils.get_node_data(node["name"]) sourceid = n["id"] # link -target node id s = utils.get_switch_data(self.switch) targetid = s["id"] # apply the Qos to the interface if "qos" in node: qos = self.getqos(node["qos"]) tc.config_qos(tapif, qos) # store the link endpoints in array (for UI drawing) self.links.append({ "source": sourceid, "target": targetid, "source-name": node["name"], "target-name": self.switch }) # update in DB self.docid = utils.link_t.insert({ 'id': utils.generate_id(), 'source': node["name"], 'target': self.switch, 'source-id': sourceid, 'target-id': targetid, 'if1': node_interface, 'if2': tapif, 'qos': qos, })
def __init__(self, data, network): self.uuid = None self.id = utils.generate_id() self.name = data["name"] self.img = data["image"] self.status = "initialized" if "mac" in data: self.mac = data["mac"] else: self.mac = None if 'ip' in data: self.ip = data["ip"] else: self.ip = network.getip() # DB Updation self.docid = utils.node_t.insert({'id': self.id, 'name': self.name, 'img': self.img, 'ip': self.ip, 'mac': self.mac, 'status': self.status})
def __init__(self, data): self.id = utils.generate_id() self.src_switch = data["switches"][0] self.dst_switch = data["switches"][1] self.links = []
def test_generate_id_again(self): self.assertEqual(utils.generate_id(), 1)
def test_generate_id(self): self.assertEqual(utils.generate_id(), 0)
def test_reset_generate(self): utils.reset_id() self.assertEqual(utils.generate_id(), 0)