Ejemplo n.º 1
0
 def do_save(self, cmd_input):
     if self.json_body == None:
         print "please apply match"
     else :
         file_path = global_value.FLOW_PATH + "/" + self.input_match["table_id"] + "-" + self.input_match["id"] + ".json"
         utils.config_json_write(file_path, self.json_body)
         print "save : " + file_path
Ejemplo n.º 2
0
        def get_physical_hosts(self):
	        
                from utils import get_hosts
                host_data = get_hosts(self.controller_IP, "8080","")
                if host_data:
                        count = 1
                        print "Receiving physical network data from SDN controller ..."
			for host in  host_data['hostConfig']:
				IP = host['networkAddress']
                                MAC = host['dataLayerAddress']
                                Service = 'Streaming_'+str(count)
                                Status = 'Active'
                                physical ={'MAC':MAC, 'IP':IP, 'Service':Service, 'Status':Status}
                                self.physical_hosts.append(physical) 
                                print "Get physical host:"+str(physical)
                                count = count + 1
                else:            
                    print "No physical network info. Check SDN controller"

                from utils import config_json_read
		data = config_json_read(host_path)
                data['Physical_hosts']=self.physical_hosts

                #write hosts information in host.json file
                from utils import config_json_write
                config_json_write(host_path,data)
                print "Received host information"
    def do_alias(self, line):
        from utils import refresh_alias_json_db
        from utils import config_json_read 
        from utils import config_json_write
        from global_value import CONF_PATH 
        #read and mode and write json db
        file_path = CONF_PATH+"/"+self.controller_uid+".json"
        try :
            read_json = config_json_read(file_path)
            for dpid_list in read_json['controllers']['switchs']:
                if dpid_list['dpid'] == self.dpid:
                    #line command check
                    dpid_list['sw_alias'] = line
                    print "change switch alias"
                    break
            print self.hp_sw_alias_db
            config_json_write(file_path, read_json)
            refresh_alias_json_db(self.ip, self.port, self.token, None, None)
            self.sw_name = line
        except Exception:
            traceback.print_exc()
            return None

        #check line
        self.prompt = "Controller("+line+"): " 
        print "change datapath name",line
Ejemplo n.º 4
0
    def get_physical_hosts(self):

        from utils import get_hosts
        host_data = get_hosts(self.controller_IP, "8080", "")
        if host_data:
            count = 1
            print "Receiving physical network data from SDN controller ..."
            for host in host_data['hostConfig']:
                IP = host['networkAddress']
                MAC = host['dataLayerAddress']
                Service = 'Streaming_' + str(count)
                Status = 'Active'
                physical = {
                    'MAC': MAC,
                    'IP': IP,
                    'Service': Service,
                    'Status': Status
                }
                self.physical_hosts.append(physical)
                print "Get physical host:" + str(physical)
                count = count + 1
        else:
            print "No physical network info. Check SDN controller"

        from utils import config_json_read
        data = config_json_read(host_path)
        data['Physical_hosts'] = self.physical_hosts

        #write hosts information in host.json file
        from utils import config_json_write
        config_json_write(host_path, data)
        print "Received host information"
Ejemplo n.º 5
0
 def set_controller_alias(self, name):
     import registered_controller
     import utils, global_value
     file_path = global_value.CONF_PATH + "/" + self.ip + ".json"
     self.controller_db['con_alias'] = name
     utils.config_json_write(file_path, self.controller_db)
     
     # registrered_controller_db write
     regi_controller = registered_controller.Registered_controller()
     regi_controller.search_controller(self.ip, self.port, name)
     self.prompt = "Controller(" + name + ") # "
Ejemplo n.º 6
0
        def clearDB(self):	
            from utils import config_json_read
	    data = config_json_read(host_path)
	    data['F_VMs'] = ''
	    data['P_VMs'] = ''
            data['Physical_hosts'] = ''

 	    from utils import config_json_write
	    config_json_write(host_path, data)
	    
            print "Cleared all data in database"
Ejemplo n.º 7
0
    def clearDB(self):
        from utils import config_json_read
        data = config_json_read(host_path)
        data['F_VMs'] = ''
        data['P_VMs'] = ''
        data['Physical_hosts'] = ''

        from utils import config_json_write
        config_json_write(host_path, data)

        print "Cleared all data in database"
Ejemplo n.º 8
0
def create_controller_db(file_path, ip, port, token):
    from utils import config_json_write
    from onos_api.onos_controller_api import onos_api_switches

    switches = {}
    switch_data = onos_api_switches(ip, port, token)["devices"]
    for switch in switch_data:
        if switch["role"] == "MASTER":
            switches[switch["id"]] = switch["id"]

    config_json_write(file_path, switches)
Ejemplo n.º 9
0
        def update_VM_info(self):
                print "Updating latest VM data in database ..."

		for port in self.neut_client.list_ports()['ports']:
			mac_address = port['mac_address']
                        fixed_ip = port['fixed_ips'][0]['ip_address']
                        self.virtual_hosts[fixed_ip] = mac_address


		ips =  self.nova_client.floating_ips.list()
		length = len(ips)
                
                f_count = 1
                p_count = 1
		n = 1

                for x in range(length):
			fixed_ip = ips[x].fixed_ip
                        net = fixed_ip.split(".")
                        subnet = net[2]
                        if subnet == "20":
				floating_ip = ips[x].ip
                                mac_floating = self.virtual_hosts[floating_ip]
                                service = 'Streaming_'+str(p_count)
                                status = 'Active'
                                vm = {'IP':floating_ip, 'MAC':mac_floating, 'Service':service, 'Status':status, "Fixed_IP":fixed_ip}
       				self.P_VM.append(vm)
                                if n == 2:
                                    p_count = p_count + 1
                                    n = 1
                                else:
                                    n = n + 1
    			
                        elif subnet == "10": 
				floating_ip = ips[x].ip
        			mac_floating = self.virtual_hosts[floating_ip]
                                service = 'Streaming_'+str(f_count)
                                status = 'Active'
                                vm = {'IP':floating_ip, 'MAC':mac_floating, 'Service':service, 'Status':status, "Fixed_IP":fixed_ip}
        			self.F_VM.append(vm)
                                f_count = f_count + 1

  		from utils import config_json_read
		data = config_json_read(host_path)
		data['F_VMs'] = self.F_VM
		data['P_VMs'] = self.P_VM

 		from utils import config_json_write
		config_json_write(host_path, data)
		print "Successfully updated."
Ejemplo n.º 10
0
def controller_db_init(ip, port, token):
    file_path = global_value.CONF_PATH + "/" + ip + ".json"
    # logger.debug(file_path)
    import os.path

    controller_db = dict()

    if os.path.isfile(file_path):
        controller_db = utils.config_json_read(file_path)
    if controller_db == None or len(controller_db) == 0:
        open_flie = open(file_path, "a+")
        controller_db = {"ip": ip, "con_alias": ip, "sw_alias": {}}
    controller_db["sw_alias"] = set_sw_alias(ip, port, token, controller_db.get("sw_alias"))
    utils.config_json_write(file_path, controller_db)
    return controller_db
    def search_controller(self, ip, port, c_name):
        from utils import config_json_read
        from utils import config_json_write

        file_path = CONF_PATH + REG_CONF_FILE
        try:
            read_json = config_json_read(file_path)
            for index in range(len(read_json["controllers"])):
                if read_json["controllers"][index]["port"] == port and read_json["controllers"][index]["ip"] == ip:
                    read_json["controllers"][index]["name"] = c_name
                    print read_json
                    config_json_write(file_path, read_json)

        except Exception:
            traceback.print_exc()
            return None
Ejemplo n.º 12
0
def update_controller_db(file_path, ip, port, token):
    from utils import config_json_read, config_json_write
    from onos_api.onos_controller_api import onos_api_switches

    latest_switches = {}
    latest_sw_data = onos_api_switches(ip, port, token)["devices"]
    switches = config_json_read(file_path)
    for switch in latest_sw_data:
        if switch["role"] == "MASTER":
            try:
                sw_alias = switches[switch["id"]]
            except KeyError:
                sw_alias = switch["id"]
            finally:
                latest_switches[switch["id"]] = sw_alias

    config_json_write(file_path, latest_switches)
Ejemplo n.º 13
0
    def do_alias(self, cmd_line):
        from utils import config_json_read, config_json_write
        from global_value import CONF_PATH, REG_CONF_FILE

        reg_con_path = CONF_PATH+REG_CONF_FILE
        if cmd_line:
            try:
                read_con_json = config_json_read(reg_con_path)
                for controller in read_con_json['controllers']:
                    if controller['ip'] == self.ip:
                        controller['name'] = cmd_line
                        config_json_write(reg_con_path, read_con_json)

                self.prompt = cmd_line
                self.prompt = "Controller("+cmd_line+"): " 
            except Exception:
                traceback.print_exc()
                return None
 def do_alias(self, cmd_line):        	
     from utils import config_json_read, config_json_write
     from onos_api.onos_utils import return_sw_names
     if cmd_line:
         switch_names = return_sw_names(self.file_path)
         if cmd_line in switch_names:
             print"Duplicated name, please input another name!!!"
         else:
             try:
                 switches = config_json_read(self.file_path)
                 switches[self.sw_dpid] = cmd_line
                 config_json_write(self.file_path, switches)
                 self.prompt = "#switch("+cmd_line+"): " 
             except Exception:
                 traceback.print_exc()
                 return None
     else:
         print "Please input switch alias"
Ejemplo n.º 15
0
    def set_alias(self, input_alias):
        file_path = global_value.CONF_PATH +"/" + self.ip + ".json"
        controller_db = utils.config_json_read(file_path)
        sw_alias_db = controller_db["sw_alias"]
        temp_dpid = sw_alias_db.get(input_alias)
        if temp_dpid:
            yn = "you want replace \"" + input_alias + "\":\"" + temp_dpid + "\" -> \"" + input_alias + "\":\"" + self.dpid + "\" ? (y/n) # "
            if not yn.lower() == "y" :
                print "cancle replace"
                return None
            sw_alias_db[temp_dpid] = temp_dpid

        sw_alias_db.pop(self.alias)
        sw_alias_db[input_alias] = self.dpid
            

        
        utils.config_json_write(file_path, controller_db)
        self.prompt = "Switch(" + input_alias + ") # "
Ejemplo n.º 16
0
    def do_alias(self, cmd_line):
        from utils import refresh_alias_json_db
        from utils import config_json_write
        from utils import config_json_read
        from global_value import CONF_PATH 
        
        reg_cont = Registered_controller()
        file_path = CONF_PATH+"/"+self.controller_uid+".json"
        try :
            read_json = config_json_read(file_path)
            read_json['controllers']['con_alias'] = cmd_line
            config_json_write(file_path, read_json)
            refresh_alias_json_db(self.ip, self.port, self.token, None, None)
            self.prompt = cmd_line
            self.prompt = "Controller("+cmd_line+"): " 
            reg_cont.search_controller(self.ip, self.port, cmd_line)

        except Exception:
            traceback.print_exc()
            return None
 def do_save_flow(self, line):
     from global_value import FLOW_PATH
     from utils import config_json_write
     file_path = FLOW_PATH+'/'+self.ip+'_flow.json'
     config_json_write(file_path, self.make_json_flow)
     print "saved"
    def do_save_flow(self, line):
        from utils import config_json_write
        file_path = FLOW_PATH+'/'+self.flow_name 
	config_json_write(file_path, self.make_json_flow)
        print "save"
Ejemplo n.º 19
0
    def update_VM_info(self):
        print "Updating latest VM data in database ..."

        for port in self.neut_client.list_ports()['ports']:
            mac_address = port['mac_address']
            fixed_ip = port['fixed_ips'][0]['ip_address']
            self.virtual_hosts[fixed_ip] = mac_address

        ips = self.nova_client.floating_ips.list()
        length = len(ips)

        f_count = 1
        p_count = 1
        n = 1

        for x in range(length):
            fixed_ip = ips[x].fixed_ip
            net = fixed_ip.split(".")
            subnet = net[2]
            if subnet == "20":
                floating_ip = ips[x].ip
                mac_floating = self.virtual_hosts[floating_ip]
                service = 'Streaming_' + str(p_count)
                status = 'Active'
                vm = {
                    'IP': floating_ip,
                    'MAC': mac_floating,
                    'Service': service,
                    'Status': status,
                    "Fixed_IP": fixed_ip
                }
                self.P_VM.append(vm)
                if n == 2:
                    p_count = p_count + 1
                    n = 1
                else:
                    n = n + 1

            elif subnet == "10":
                floating_ip = ips[x].ip
                mac_floating = self.virtual_hosts[floating_ip]
                service = 'Streaming_' + str(f_count)
                status = 'Active'
                vm = {
                    'IP': floating_ip,
                    'MAC': mac_floating,
                    'Service': service,
                    'Status': status,
                    "Fixed_IP": fixed_ip
                }
                self.F_VM.append(vm)
                f_count = f_count + 1

        from utils import config_json_read
        data = config_json_read(host_path)
        data['F_VMs'] = self.F_VM
        data['P_VMs'] = self.P_VM

        from utils import config_json_write
        config_json_write(host_path, data)
        print "Successfully updated."