<commit_before>#!/usr/bin/env python
#
# Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import yaml
import toml
import glob
import os
from argparse import ArgumentParser
from fabric.api import local, settings

CONFIG_DIR = '/tmp/bgperf'
BR_NAME = 'bgperf_br'

conf = {}

class CmdBuffer(list):
    def __init__(self, delim='\n'):
        super(CmdBuffer, self).__init__()
        self.delim = delim

    def __lshift__(self, value):
        self.append(value)

    def __str__(self):
        return self.delim.join(self)


def run_gobgp(conf):
    config = {'Global': {'GlobalConfig': {'As': conf['target']['as'], 'RouterId': conf['target']['router-id'], 'Port': -1}}}
    for peer in conf['tester'].itervalues():
        n = {'NeighborConfig': {
            'NeighborAddress': peer['local-address'].split('/')[0],
            'PeerAs': peer['as'],
            },
            'Transport': {
                'TransportConfig': {
                    'LocalAddress': conf['target']['local-address'].split('/')[0],
                },
            },
            'RouteServer': {
                'RouteServerConfig': {
                    'RouteServerClient': True,
                },
            },
        }
        if 'Neighbors' not in config:
            config['Neighbors'] = {'NeighborList': []}
        config['Neighbors']['NeighborList'].append(n)

    with open('{0}/{1}'.format(CONFIG_DIR, 'gobgpd.conf'), 'w') as f:
        f.write(toml.dumps(config))


    if 'docker' in conf['target']:
        DOCKER_SHARED_DIR = '/root/shared_volume'
        name = 'gobgp'
        if 'name' in conf['target']['docker']:
            name = conf['target']['docker']['name']

        image = 'osrg/gobgp'
        if 'image' in conf['target']['docker']:
            image = conf['target']['docker']['image']

        c = CmdBuffer(' ')
        c << 'docker run --privileged=true'
        c << '-v {0}:{1}'.format(CONFIG_DIR, DOCKER_SHARED_DIR)
        c << '--name {0} -id {1}'.format(name, image)
        with settings(warn_only=True):
            local('docker rm -f {0}'.format(name))
        local(str(c))<commit_msg>bgperf.py: catch up to the latest gobgp configuration<commit_after>#!/usr/bin/env python
#
# Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import yaml
import toml
import glob
import os
from argparse import ArgumentParser
from fabric.api import local, settings

CONFIG_DIR = '/tmp/bgperf'
BR_NAME = 'bgperf_br'

conf = {}

class CmdBuffer(list):
    def __init__(self, delim='\n'):
        super(CmdBuffer, self).__init__()
        self.delim = delim

    def __lshift__(self, value):
        self.append(value)

    def __str__(self):
        return self.delim.join(self)


def run_gobgp(conf):
    config = {'global': {
                'config': {
                    'as': conf['target']['as'],
                    'router-id': conf['target']['router-id']
                },
            }
    for peer in conf['tester'].itervalues():
        n = {'config': {
                'neighbor-address': peer['local-address'].split('/')[0],
                'peer-as': peer['as']
                },
             'transport': {
                'config': {
                    'local-address': conf['target']['local-address'].split('/')[0],
                },
            },
            'route-server': {
                'config': {
                    'route-server-client': True,
                },
            },
        }
        if 'neighbors' not in config:
            config['neighbors'] = []
        config['neighbors'].append(n)

    with open('{0}/{1}'.format(CONFIG_DIR, 'gobgpd.conf'), 'w') as f:
        f.write(toml.dumps(config))


    if 'docker' in conf['target']:
        DOCKER_SHARED_DIR = '/root/shared_volume'
        name = 'gobgp'
        if 'name' in conf['target']['docker']:
            name = conf['target']['docker']['name']

        image = 'osrg/gobgp'
        if 'image' in conf['target']['docker']:
            image = conf['target']['docker']['image']

        c = CmdBuffer(' ')
        c << 'docker run --privileged=true'
        c << '-v {0}:{1}'.format(CONFIG_DIR, DOCKER_SHARED_DIR)
        c << '--name {0} -id {1}'.format(name, image)
        with settings(warn_only=True):
            local('docker rm -f {0}'.format(name))
        local(str(c))
{'fraction_non_alphanumeric': 0.1502122162760657, 'fraction_numerical': 0.006458756228086363, 'mean_word_length': 2.3477455219271155, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7081970', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1585, 'n_words': 435}