Beispiel #1
0
 def pcf_start(self):
     cmds=cmds_dict['pcf']
     connector = RemoteConnect(target_addr)
     print('Start to activate PCF')
     connector.ssh_direct(cmds,target_username,target_password)
     self.put_data('pcf')
     print('Finish to activate PCF')
Beispiel #2
0
 def amf_start(self):
     connector = RemoteConnect(self.amf_instance_ip)
     cmds = ['sudo nohup ./stage3/bin/amf\n', 'exit\n']
     print('Start to activate AMF')
     connector.ssh_jump(cmds)
     cmds = ['sudo service VnfDetect start\n', 'exit\n']
     connector.ssh_jump(cmds)
     print('Finish activate AMF')
Beispiel #3
0
 def upf_start(self):
     print('Start to activate UPF')
     connector = RemoteConnect(self.upf_instance_ip)
     connector.transport_dir()
     cmds = [
         'chmod 777 stage3/src/upf/build/bin/free5gc-upfd\n',
         'cd /home/ubuntu/stage3/gtp5g\n', 'make\n', 'sudo make install\n',
         'cd /home/ubuntu/stage3/src/upf/build\n',
         'sudo nohup ./bin/free5gc-upfd\n', 'exit\n'
     ]
     connector.ssh_jump(cmds)
     #time.sleep(1)
     cmds = ['sudo service VnfDetect start\n', 'exit\n']
     connector.ssh_jump(cmds)
     print('Finish activate UPF')
Beispiel #4
0
 def nssf_start(self):
     connector = RemoteConnect(self.nssf_instance_ip)
     cmds = ['sudo nohup ./stage3/bin/nssf\n', 'exit\n']
     print('Start to activate NSSF')
     connector.ssh_jump(cmds)
     #time.sleep(1)
     cmds = ['sudo service VnfDetect start\n', 'exit\n']
     connector.ssh_jump(cmds)
     print('Finish activate NSSF')
Beispiel #5
0
 def ausf_terminate(self):
     self.put_data('ausf')
     cmds = ['kill -9 $(pidof ./all_in_one/bin/ausf)\n','exit\n']
     connector = RemoteConnect(target_addr)
     connector.ssh_direct(cmds,target_username,target_password)
     print('AUSF terminated')
Beispiel #6
0
 def upf_terminate(self):
     self.put_data('upf')
     cmds = ['kill -9 $(pidof ./bin/free5gc-upfd)\n','exit\n']
     connector = RemoteConnect(target_addr)
     connector.ssh_direct(cmds,target_username,target_password)
     print('UPF terminated')
Beispiel #7
0
 def __init__(self):
     self.r = redis.Redis(host='localhost', port=6379, db=0)
     self.connector = RemoteConnect(target_addr)
Beispiel #8
0
class EMS():
    def __init__(self):
        self.r = redis.Redis(host='localhost', port=6379, db=0)
        self.connector = RemoteConnect(target_addr)

    def put_data(self, tunnel_name, flag):
        #r = redis.Redis(host='localhost', port=6379, db=0)
        self.r.set(tunnel_name, flag)

    def ResetUPF(self):
        cmds = cmds_dict['upf']
        cmds.insert(0, 'kill -9 $(pidof ./bin/free5gc-upfd)\n')
        self.put_data('upf', 'on')
        self.connector.ssh_direct(cmds, target_username, target_password)
        self.put_data('upf', 'off')

    def ResetAMF(self):
        cmds = cmds_dict['amf']
        cmds.insert(0, 'kill -9 $(pidof ./all_in_one/bin/amf)\n')
        self.put_data('amf', 'on')
        self.connector.ssh_direct(cmds, target_username, target_password)
        self.put_data('amf', 'off')

    def ResetSMF(self):
        cmds = cmds_dict['smf']
        cmds.insert(0, 'kill -9 $(pidof ./all_in_one/bin/smf)\n')
        self.put_data('smf', 'on')
        self.connector.ssh_direct(cmds, target_username, target_password)
        self.put_data('smf', 'off')

    def ResetUDR(self):
        cmds = cmds_dict['udr']
        cmds.insert(0, 'kill -9 $(pidof ./all_in_one/bin/udr)\n')
        self.put_data('udr', 'on')
        self.connector.ssh_direct(cmds, target_username, target_password)
        self.put_data('udr', 'off')

    def ResetPCF(self):
        cmds = cmds_dict['pcf']
        cmds.insert(0, 'kill -9 $(pidof ./all_in_one/bin/pcf)\n')
        self.put_data('pcf', 'on')
        self.connector.ssh_direct(cmds, target_username, target_password)
        self.put_data('pcf', 'off')

    def ResetUDM(self):
        cmds = cmds_dict['udm']
        cmds.insert(0, 'kill -9 $(pidof ./all_in_one/bin/udm)\n')
        self.put_data('udm', 'on')
        self.connector.ssh_direct(cmds, target_username, target_password)
        self.put_data('udm', 'off')

    def ResetNSSF(self):
        cmds = cmds_dict['nssf']
        cmds.insert(0, 'kill -9 $(pidof ./all_in_one/bin/nssf)\n')
        self.put_data('nssf', 'on')
        self.connector.ssh_direct(cmds, target_username, target_password)
        self.put_data('nssf', 'off')

    def ResetAUSF(self):
        cmds = cmds_dict['ausf']
        cmds.insert(0, 'kill -9 $(pidof ./all_in_one/bin/ausf)\n')
        self.put_data('ausf', 'on')
        self.connector.ssh_direct(cmds, target_username, target_password)
        self.put_data('ausf', 'off')

    def HealPnf(self, pnf_name):
        print('EM detected {} fail'.format(pnf_name))
        print('EM start to heal {}'.format(pnf_name))
        if pnf_name == 'nrf':
            self.ResetUPF()
            cmds = cmds_dict[pnf_name]
            self.connector.ssh_direct(cmds, target_username, target_password)
            self.ResetAMF()
            self.ResetSMF()
            self.resetUDR()
            self.ResetPCF()
            self.ResetUDM()
            self.ResetNSSF()
            self.ResetAUSF()
        elif pnf_name == 'upf':
            cmds = cmds_dict[pnf_name]
            self.connector.ssh_direct(cmds, target_username, target_password)
            self.ResetSMF()
        elif pnf_name == 'smf':
            self.ResetUPF()
            cmds = cmds_dict[pnf_name]
            self.connector.ssh_direct(cmds, target_username, target_password)
        else:
            cmds = cmds_dict[pnf_name]
            self.connector.ssh_direct(cmds, target_username, target_password)
        print('EM finish heal {}'.format(pnf_name))

    def DetectPnf(self, pnf_name):
        #lock = 'on'
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(target_addr,
                    22,
                    username=target_username,
                    password=target_password)
        if pnf_name == 'upf':
            cmd = 'ps -aux | grep ./bin/free5gc-upfd'
        else:
            cmd = 'ps -aux | grep ./all_in_one/bin/%s' % pnf_name
        #r = redis.Redis(host='localhost', port=6379, db=0)

        while (1):
            time.sleep(1)
            lock = self.r.get(pnf_name)
            if lock == None:
                continue
            else:
                lock = lock.decode()
            #print('lock:{}'.format(lock))
            if lock == 'terminate':
                print('Terminate EM')
                sys.exit(1)
            if lock == 'on':
                #print('match')
                continue
            stdin, stdout, stderr = ssh.exec_command(cmd)
            out = stdout.read().decode().split("\n")
            if len(out) != 4:
                self.HealPnf(pnf_name)