예제 #1
0
    def run(self, conf, brname=''):
        ctn = super(GoBGP, self).run(brname)
        config = {}
        config['global'] = {
            'config': {
                'as': conf['monitor']['as'],
                'router-id': conf['monitor']['router-id'],
            },
        }
        config ['neighbors'] = [{'config': {'neighbor-address': conf['target']['local-address'].split('/')[0],
                                            'peer-as': conf['target']['as']},
                                 'transport': {'config': {'local-address': conf['monitor']['local-address'].split('/')[0]}},
                                 'timers': {'config': {'connect-retry': 10}}}]
        with open('{0}/{1}'.format(self.host_dir, 'gobgpd.conf'), 'w') as f:
            f.write(yaml.dump(config))
        self.config_name = 'gobgpd.conf'
        startup = '''#!/bin/bash
ulimit -n 65536
ip a add {0} dev eth1
gobgpd -t yaml -f {1}/{2} -l {3} > {1}/gobgpd.log 2>&1
'''.format(conf['monitor']['local-address'], self.guest_dir, self.config_name, 'info')
        filename = '{0}/start.sh'.format(self.host_dir)
        with open(filename, 'w') as f:
            f.write(startup)
        os.chmod(filename, 0777)
        i = dckr.exec_create(container=self.name, cmd='{0}/start.sh'.format(self.guest_dir))
        dckr.exec_start(i['Id'], detach=True)
        self.config = conf
        return ctn
예제 #2
0
    def run(self, conf, brname=''):
        ctn = super(GoBGP, self).run(brname)
        config = {}
        config['global'] = {
            'config': {
                'as': conf['monitor']['as'],
                'router-id': conf['monitor']['router-id'],
            },
        }
        config['neighbors'] = [{
            'config': {
                'neighbor-address':
                conf['target']['local-address'].split('/')[0],
                'peer-as': conf['target']['as']
            },
            'transport': {
                'config': {
                    'local-address':
                    conf['monitor']['local-address'].split('/')[0]
                }
            },
            'timers': {
                'config': {
                    'connect-retry': 10
                }
            }
        }]
        with open('{0}/{1}'.format(self.host_dir, 'gobgpd.conf'), 'w') as f:
            f.write(yaml.dump(config))
        self.config_name = 'gobgpd.conf'
        startup = '''#!/bin/bash
ulimit -n 65536
ip a add {0} dev eth1
gobgpd -t yaml -f {1}/{2} -l {3} > {1}/gobgpd.log 2>&1
'''.format(conf['monitor']['local-address'], self.guest_dir, self.config_name,
           'info')
        filename = '{0}/start.sh'.format(self.host_dir)
        with open(filename, 'w') as f:
            f.write(startup)
        os.chmod(filename, 0777)
        i = dckr.exec_create(container=self.name,
                             cmd='{0}/start.sh'.format(self.guest_dir))
        dckr.exec_start(i['Id'], detach=True)
        self.config = conf
        return ctn
예제 #3
0
    def run(self, conf, target, brname=''):
        super(Tester, self).run(brname)

        startup = ['''#!/bin/bash
ulimit -n 65536''']

        peers = conf.get('tester', {}).values()

        for p in peers:
            with open('{0}/{1}.conf'.format(self.host_dir, p['router-id']),
                      'w') as f:
                local_address = p['local-address'].split('/')[0]
                config = '''neighbor {0} {{
    peer-as {1};
    router-id {2};
    local-address {3};
    local-as {4};
    static {{
'''.format(target['local-address'].split('/')[0], target['as'], p['router-id'],
                local_address, p['as'])
                f.write(config)
                for path in p['paths']:
                    f.write('      route {0} next-hop {1};\n'.format(
                        path, local_address))
                f.write('''   }
}''')
            startup.append('''env exabgp.log.destination={0}/{1}.log \
exabgp.daemon.daemonize=true \
exabgp.daemon.user=root \
exabgp {0}/{1}.conf'''.format(self.guest_dir, p['router-id']))

        for p in peers:
            startup.append('ip a add {0} dev eth1'.format(p['local-address']))

        filename = '{0}/start.sh'.format(self.host_dir)
        with open(filename, 'w') as f:
            f.write('\n'.join(startup))
        os.chmod(filename, 0777)
        i = dckr.exec_create(container=self.name,
                             cmd='{0}/start.sh'.format(self.guest_dir))
        cnt = 0
        for lines in dckr.exec_start(i['Id'], stream=True):
            for line in lines.strip().split('\n'):
                cnt += 1
                if cnt % 2 == 1:
                    if cnt > 1:
                        rm_line()
                    print 'tester booting.. ({0}/{1})'.format(
                        cnt / 2 + 1, len(conf.get('tester', {}).values()))
예제 #4
0
    def run(self, conf, brname=''):
        super(Tester, self).run(brname)

        startup = ['''#!/bin/bash
ulimit -n 65536''']

        peers = conf['tester'].values()

        for p in peers:
            with open('{0}/{1}.conf'.format(self.host_dir, p['router-id']), 'w') as f:
                local_address = p['local-address'].split('/')[0]
                config = '''neighbor {0} {{
    peer-as {1};
    router-id {2};
    local-address {3};
    local-as {4};
    static {{
'''.format(conf['target']['local-address'].split('/')[0], conf['target']['as'],
               p['router-id'], local_address, p['as'])
                f.write(config)
                for path in p['paths']:
                    f.write('      route {0} next-hop {1};\n'.format(path, local_address))
                f.write('''   }
}''')
            startup.append('''env exabgp.log.destination={0}/{1}.log \
exabgp.daemon.daemonize=true \
exabgp.daemon.user=root \
exabgp {0}/{1}.conf'''.format(self.guest_dir, p['router-id']))

        for p in peers:
            startup.append('ip a add {0} dev eth1'.format(p['local-address']))

        filename = '{0}/start.sh'.format(self.host_dir)
        with open(filename, 'w') as f:
            f.write('\n'.join(startup))
        os.chmod(filename, 0777)
        i = dckr.exec_create(container=self.name, cmd='{0}/start.sh'.format(self.guest_dir))
        cnt = 0
        for lines in dckr.exec_start(i['Id'], stream=True):
                for line in lines.strip().split('\n'):
                    cnt += 1
                    if cnt % 2 == 1:
                        if cnt > 1:
                            rm_line()
                        print 'tester booting.. ({0}/{1})'.format(cnt/2 + 1, len(conf['tester']))
예제 #5
0
 def local(self, cmd, stream=False):
     i = dckr.exec_create(container=self.name, cmd=cmd)
     return dckr.exec_start(i['Id'], tty=True, stream=stream)
 def local(self, cmd, stream=False, detach=False):
     i = dckr.exec_create(container=self.name, cmd=cmd)
     return dckr.exec_start(i['Id'], stream=stream, detach=detach)
예제 #7
0
 def local(self, cmd, stream=False):
     i = dckr.exec_create(container=self.name, cmd=cmd)
     return dckr.exec_start(i['Id'], tty=True, stream=stream)
예제 #8
0
파일: mrt_tester.py 프로젝트: pierky/bgperf
    def run(self, conf, target, brname=''):
        ctn = super(GoBGP, self).run(brname)

        conf = conf['tester'].values()[0]

        config = {
            'global': {
                'config': {
                    'as': conf['as'],
                    'router-id': conf['router-id'],
                }
            },
        }

        with open('{0}/{1}.conf'.format(self.host_dir, self.name), 'w') as f:
            f.write(yaml.dump(config, default_flow_style=False))
            self.config_name = '{0}.conf'.format(self.name)

        startup = '''#!/bin/bash
ulimit -n 65536
ip a add {0} dev eth1
gobgpd -t yaml -f {1}/{2} -l {3} > {1}/gobgpd.log 2>&1
'''.format(conf['local-address'], self.guest_dir, self.config_name, 'info')
        filename = '{0}/start.sh'.format(self.host_dir)

        with open(filename, 'w') as f:
            f.write(startup)
        os.chmod(filename, 0777)
        i = dckr.exec_create(container=self.name,
                             cmd='{0}/start.sh'.format(self.guest_dir))
        dckr.exec_start(i['Id'], detach=True, socket=True)
        mrtfile = '{0}/{1}'.format(self.host_dir,
                                   os.path.basename(conf['mrt-file']))
        shutil.copyfile(conf['mrt-file'], mrtfile)
        cmd = ['gobgp', 'mrt']
        if conf.get('only-best', False):
            cmd.append('--only-best')
        cmd += [
            'inject',
            'global', '{0}/{1}'.format(self.guest_dir,
                                       os.path.basename(conf['mrt-file']))
        ]
        if 'count' in conf:
            cmd.append(str(conf['count']))
        if 'skip' in conf:
            cmd.append(str(conf['skip']))
        i = dckr.exec_create(container=self.name, cmd=cmd)
        dckr.exec_start(i['Id'], detach=False, socket=True)

        config['neighbors'] = [{
            'config': {
                'neighbor-address': target['local-address'].split('/')[0],
                'peer-as': target['as'],
            },
        }]

        with open('{0}/{1}.conf'.format(self.host_dir, self.name), 'w') as f:
            f.write(yaml.dump(config, default_flow_style=False))

        i = dckr.exec_create(container=self.name,
                             cmd=['pkill', '-SIGHUP', 'gobgpd'])
        dckr.exec_start(i['Id'], detach=False, socket=True)

        return ctn