Exemplo n.º 1
0
    def connect_olt(self, host_and_port, device_id, is_init=True):
        self.device_id = device_id
        self.grpc_client.connect(host_and_port)
        self.stub = bal_pb2.BalStub(self.grpc_client.channel)
        self.ind_stub = bal_indications_pb2.BalGetIndStub(self.grpc_client.channel)
        self.olt.running = True

        # Right now Bi-Directional GRPC support is not there in grpc-c.
        # This code may be needed when bidirectional supported added
        # in GRPC-C
        if is_init == True:
            init = bal_pb2.BalInit()
            try:
                os.environ["SERVICE_HOST_IP"]
                adapter_ip = os.environ["SERVICE_HOST_IP"]
            except Exception as e:
                self.log.info('voltha-is-running-in-non-docker-container-environment')
                adapter_ip = get_my_primary_local_ipv4()

            ip_port = []
            ip_port.append(str(adapter_ip))
            ip_port.append(":")
            ip_port.append(str(ADAPTER_PORT))
            init.voltha_adapter_ip_port ="".join(ip_port)
            self.log.info('Adapter-port-IP', init.voltha_adapter_ip_port)
            self.log.info('connecting-olt', host_and_port=host_and_port,
                          init_details=init)
            yield self.stub.BalApiInit(init, timeout=GRPC_TIMEOUT)
Exemplo n.º 2
0
    def connect_olt(self, host_and_port, device_id, is_init=True):
        self.device_id = device_id
        self.grpc_client.connect(host_and_port)
        self.stub = bal_pb2.BalStub(self.grpc_client.channel)
        self.ind_stub = bal_indications_pb2.BalGetIndStub(self.grpc_client.channel)
        self.asfvolt_stub = asfvolt_pb2.AsfvoltStub(self.grpc_client.channel)
        self.olt.running = True

        # Right now Bi-Directional GRPC support is not there in grpc-c.
        # This code may be needed when bidirectional supported added
        # in GRPC-C
        if is_init == True:
            init = bal_pb2.BalInit()
            try:
                os.environ["SERVICE_HOST_IP"]
                adapter_ip = os.environ["SERVICE_HOST_IP"]
            except Exception as e:
                self.log.info('voltha-is-running-in-non-docker-container-environment')
                adapter_ip = get_my_primary_local_ipv4()

            ip_port = []
            ip_port.append(str(adapter_ip))
            ip_port.append(":")
            ip_port.append(str(ADAPTER_PORT))
            init.voltha_adapter_ip_port ="".join(ip_port)
            self.log.info('Adapter-port-IP', init.voltha_adapter_ip_port)
            self.log.info('connecting-olt', host_and_port=host_and_port,
                          init_details=init)
            yield self.stub.BalApiInit(init, timeout=GRPC_TIMEOUT)
Exemplo n.º 3
0
Arquivo: bal.py Projeto: bm2535/voltha
    def connect_olt(self, host_and_port, device_id):
        self.device_id = device_id
        self.grpc_client.connect(host_and_port)
        self.stub = bal_pb2.BalStub(self.grpc_client.channel)
        init = bal_pb2.BalInit()
        try:
            os.environ["SERVICE_HOST_IP"]
            adapter_ip = os.environ["SERVICE_HOST_IP"]
        except Exception as e:
            self.log.info(
                'voltha is running in non docker container environment')
            adapter_ip = get_my_primary_local_ipv4()

        ip_port = []
        ip_port.append(str(adapter_ip))
        #ip_port.append("192.168.140.34")
        ip_port.append(":")
        ip_port.append(str(ADAPTER_PORT))
        init.voltha_adapter_ip_port = "".join(ip_port)
        self.log.info('Adapter port Ip', init.voltha_adapter_ip_port)
        '''
        TODO: Need to determine out what information
        needs to be sent to the OLT at this stage.
        '''
        self.log.info('connecting-olt',
                      host_and_port=host_and_port,
                      init_details=init)
        yield self.stub.BalApiInit(init)
Exemplo n.º 4
0
    def start_kafka_heartbeat(self, instance_id):
        # For heartbeat we will send a message to a specific "voltha-heartbeat"
        #  topic.  The message is a protocol buf
        # message
        message = dict(type='heartbeat',
                       voltha_instance=instance_id,
                       ip=get_my_primary_local_ipv4())
        topic = "voltha.heartbeat"

        def send_msg():
            message['ts'] = arrow.utcnow().timestamp
            kafka_proxy.send_message(topic, dumps(message))

        kafka_proxy = get_kafka_proxy()
        if kafka_proxy:
            lc = LoopingCall(send_msg)
            lc.start(10)
        else:
            self.log.error('Kafka proxy has not been created!')
Exemplo n.º 5
0
def get_endpoint_from_consul(consul_endpoint, service_name):
    """
    Get endpoint of service_name from consul.
    :param consul_endpoint: a <host>:<port> string
    :param service_name: name of service for which endpoint
                         needs to be found.
    :return: service endpoint if available, else exit.
    """
    log.debug('getting-service-info', service=service_name)

    consul = connect_to_consult(consul_endpoint)
    _, services = consul.catalog.service(service_name)

    if len(services) == 0:
        raise Exception(
            'Cannot find service {} in consul'.format(service_name))
        os.exit(1)

    """ Get host IPV4 address
    """
    local_ipv4 = get_my_primary_local_ipv4()
    """ If host IP address from where the request came in matches
        the IP address of the requested service's host IP address,
        pick the endpoint
    """
    for i in range(len(services)):
        service = services[i]
        if service['ServiceAddress'] == local_ipv4:
            log.debug("picking address locally")
            endpoint = '{}:{}'.format(service['ServiceAddress'],
                                      service['ServicePort'])
            return endpoint

    """ If service is not available locally, picak a random
        endpoint for the service from the list
    """
    service = services[randint(0, len(services) - 1)]
    endpoint = '{}:{}'.format(service['ServiceAddress'],
                              service['ServicePort'])

    return endpoint
Exemplo n.º 6
0
    def start_kafka_heartbeat(self, instance_id):
        # For heartbeat we will send a message to a specific "voltha-heartbeat"
        #  topic.  The message is a protocol buf
        # message
        message = dict(type='heartbeat',
                       voltha_instance=instance_id,
                       ip=get_my_primary_local_ipv4())
        topic = "voltha.heartbeat"

        def send_msg():
            try:
                kafka_proxy = get_kafka_proxy()
                if kafka_proxy and not kafka_proxy.is_faulty():
                    self.log.debug('kafka-proxy-available')
                    message['ts'] = arrow.utcnow().timestamp
                    self.log.debug('start-kafka-heartbeat')
                    kafka_proxy.send_message(topic, dumps(message))
                else:
                    self.log.error('kafka-proxy-unavailable')
            except Exception, e:
                self.log.exception('failed-sending-message-heartbeat', e=e)
Exemplo n.º 7
0
    def start_kafka_heartbeat(self, instance_id):
        # For heartbeat we will send a message to a specific "voltha-heartbeat"
        #  topic.  The message is a protocol buf
        # message
        message = dict(
            type='heartbeat',
            voltha_instance=instance_id,
            ip=get_my_primary_local_ipv4()
        )
        topic = "voltha.heartbeat"

        def send_msg():
            try:
                kafka_proxy = get_kafka_proxy()
                if kafka_proxy and not kafka_proxy.is_faulty():
                    self.log.debug('kafka-proxy-available')
                    message['ts'] = arrow.utcnow().timestamp
                    self.log.debug('start-kafka-heartbeat')
                    kafka_proxy.send_message(topic, dumps(message))
                else:
                    self.log.error('kafka-proxy-unavailable')
            except Exception, e:
                self.log.exception('failed-sending-message-heartbeat', e=e)
Exemplo n.º 8
0
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(base_dir)
sys.path.append(os.path.join(base_dir, '/netconf/protos/third_party'))

from common.structlog_setup import setup_logging
from common.utils.dockerhelpers import get_my_containers_name
from common.utils.nethelpers import get_my_primary_local_ipv4
from netconf.grpc_client.grpc_client import GrpcClient
from netconf.nc_server import NCServer

defs = dict(config=os.environ.get('CONFIG', './netconf.yml'),
            logconfig=os.environ.get('LOGCONFIG', './logconfig.yml'),
            consul=os.environ.get('CONSUL', 'localhost:8500'),
            external_host_address=os.environ.get('EXTERNAL_HOST_ADDRESS',
                                                 get_my_primary_local_ipv4()),
            netconf_port=os.environ.get('NETCONF_PORT', '1830'),
            server_private_key_file=os.environ.get('SERVER_PRIVATE_KEY_FILE',
                                                   'server.key'),
            server_public_key_file=os.environ.get('SERVER_PRIVATE_KEY_FILE',
                                                  'server.key.pub'),
            client_public_keys_file=os.environ.get('CLIENT_PUBLIC_KEYS_FILE',
                                                   'client_keys'),
            client_passwords_file=os.environ.get('CLIENT_PASSWORD_FILE',
                                                 'client_passwords'),
            grpc_endpoint=os.environ.get('GRPC_ENDPOINT', 'localhost:50055'),
            instance_id=os.environ.get('INSTANCE_ID',
                                       os.environ.get('HOSTNAME', '1')),
            internal_host_address=os.environ.get('INTERNAL_HOST_ADDRESS',
                                                 get_my_primary_local_ipv4()),
            work_dir=os.environ.get('WORK_DIR', '/tmp/netconf'))
Exemplo n.º 9
0
def parse_args():
    parser = argparse.ArgumentParser()

    _help = ('Path to voltha.yml config file (default: %s). '
             'If relative, it is relative to main.py of voltha.' %
             defs['config'])
    parser.add_argument('-c',
                        '--config',
                        dest='config',
                        action='store',
                        default=defs['config'],
                        help=_help)

    _help = ('Path to logconfig.yml config file (default: %s). '
             'If relative, it is relative to main.py of voltha.' %
             defs['logconfig'])
    parser.add_argument('-l',
                        '--logconfig',
                        dest='logconfig',
                        action='store',
                        default=defs['logconfig'],
                        help=_help)

    _help = 'Regular expression for extracting core number from container name (default: %s)' % defs[
        'container_name_regex']
    parser.add_argument('-X',
                        '--core-number-extractor',
                        dest='container_name_regex',
                        action='store',
                        default=defs['container_name_regex'],
                        help=_help)

    _help = '<hostname>:<port> to consul agent (default: %s)' % defs['consul']
    parser.add_argument('-C',
                        '--consul',
                        dest='consul',
                        action='store',
                        default=defs['consul'],
                        help=_help)

    _help = '<hostname>:<port> to etcd server (default: %s)' % defs['etcd']
    parser.add_argument('-e',
                        '--etcd',
                        dest='etcd',
                        action='store',
                        default=defs['etcd'],
                        help=_help)

    _help = ('<inter_core_subnet> is the subnet connecting all the voltha '
             'instances in a cluster (default: %s)' %
             defs['inter_core_subnet'])
    parser.add_argument('-V',
                        '--inter-core-subnet',
                        dest='inter_core_subnet',
                        action='store',
                        default=defs['inter_core_subnet'],
                        help=_help)

    _help = ('<pon subnet> is the subnet connecting the voltha instances'
             'with the PON network (default: %s)' % defs['pon_subnet'])
    parser.add_argument('-P',
                        '--pon-subnet',
                        dest='pon_subnet',
                        action='store',
                        default=defs['pon_subnet'],
                        help=_help)

    _help = ('<hostname> or <ip> at which Voltha is reachable from outside '
             'the cluster (default: %s)' % defs['external_host_address'])
    parser.add_argument('-E',
                        '--external-host-address',
                        dest='external_host_address',
                        action='store',
                        default=defs['external_host_address'],
                        help=_help)

    _help = (
        'port number of the GRPC service exposed by voltha (default: %s)' %
        defs['grpc_port'])
    parser.add_argument('-g',
                        '--grpc-port',
                        dest='grpc_port',
                        action='store',
                        default=defs['grpc_port'],
                        help=_help)

    _help = ('<hostname> or <ip> at which Voltha is reachable from inside the'
             'cluster (default: %s)' % defs['internal_host_address'])
    parser.add_argument('-H',
                        '--internal-host-address',
                        dest='internal_host_address',
                        action='store',
                        default=defs['internal_host_address'],
                        help=_help)

    _help = ('unique string id of this voltha instance (default: %s)' %
             defs['instance_id'])
    parser.add_argument('-i',
                        '--instance-id',
                        dest='instance_id',
                        action='store',
                        default=defs['instance_id'],
                        help=_help)

    _help = 'ETH interface to recieve (default: %s)' % defs['interface']
    parser.add_argument('-I',
                        '--interface',
                        dest='interface',
                        action='store',
                        default=defs['interface'],
                        help=_help)

    _help = 'open ssh manhole at given port'
    parser.add_argument('-m',
                        '--manhole-port',
                        dest='manhole_port',
                        action='store',
                        type=int,
                        default=None,
                        help=_help)

    _help = 'omit startup banner log lines'
    parser.add_argument('-n',
                        '--no-banner',
                        dest='no_banner',
                        action='store_true',
                        default=False,
                        help=_help)

    _help = 'do not emit periodic heartbeat log messages'
    parser.add_argument('-N',
                        '--no-heartbeat',
                        dest='no_heartbeat',
                        action='store_true',
                        default=False,
                        help=_help)

    _help = ('port number for the rest service (default: %d)' %
             defs['rest_port'])
    parser.add_argument('-R',
                        '--rest-port',
                        dest='rest_port',
                        action='store',
                        type=int,
                        default=defs['rest_port'],
                        help=_help)

    _help = "suppress debug and info logs"
    parser.add_argument('-q',
                        '--quiet',
                        dest='quiet',
                        action='count',
                        help=_help)

    _help = 'enable verbose logging'
    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose',
                        action='count',
                        help=_help)

    _help = ('use docker container name as voltha instance id'
             ' (overrides -i/--instance-id option)')
    parser.add_argument('--instance-id-is-container-name',
                        dest='instance_id_is_container_name',
                        action='store_true',
                        default=False,
                        help=_help)

    _help = ('<hostname>:<port> of the kafka broker (default: %s). (If not '
             'specified (None), the address from the config file is used' %
             defs['kafka'])
    parser.add_argument('-K',
                        '--kafka',
                        dest='kafka',
                        action='store',
                        default=defs['kafka'],
                        help=_help)

    _help = 'backend to use for config persitence'
    parser.add_argument('-b',
                        '--backend',
                        default=defs['backend'],
                        choices=['none', 'consul', 'etcd'],
                        help=_help)

    _help = "Communication mechanism to use with PON simulator"
    parser.add_argument('-S',
                        '--ponsim-comm',
                        dest='ponsim_comm',
                        default=defs['ponsim_comm'],
                        choices=['frameio', 'grpc'],
                        help=_help)

    args = parser.parse_args()

    # post-processing

    if args.instance_id_is_container_name:
        args.instance_id = get_my_containers_name()
    """
    The container external, internal IP and PON interface needs to be
    set based on the subnet data.  At this time the internal IP is not used.
    The external IP is used for inter-core communications.  If the subnets are
    set then they take precedence over the other relevant arguments (
    external and internal host as well as interface
    """
    if args.inter_core_subnet:
        m_ip = get_my_primary_local_ipv4(
            inter_core_subnet=args.inter_core_subnet)
        args.external_host_address = m_ip
        args.internal_host_address = m_ip

    if args.pon_subnet:
        args.interface = get_my_primary_interface(args.pon_subnet)

    return args
Exemplo n.º 10
0
sys.path.append(base_dir)
#sys.path.append(os.path.join(base_dir, '/netconf/protos/third_party'))

from common.structlog_setup import setup_logging
from common.utils.dockerhelpers import get_my_containers_name
from common.utils.nethelpers import get_my_primary_local_ipv4
#from netconf.grpc_client.grpc_client import GrpcClient
#from netconf.nc_server import NCServer
from dashd.dashd_impl import DashDaemon


defs = dict(
    config=os.environ.get('CONFIG', './dashd.yml'),
    consul=os.environ.get('CONSUL', 'localhost:8500'),
    external_host_address=os.environ.get('EXTERNAL_HOST_ADDRESS',
                                         get_my_primary_local_ipv4()),
    grafana_url=os.environ.get('GRAFANA_URL', 
                                        'http://*****:*****@localhost:8882/api'),
    kafka=os.environ.get('KAFKA', None),
    topic=os.environ.get('KAFKA_TOPIC', 'voltha.kpis'),
    docker_host=os.environ.get('DOCKER_HOST', None),

    fluentd=os.environ.get('FLUENTD', None),
    instance_id=os.environ.get('INSTANCE_ID', os.environ.get('HOSTNAME', '1')),
    internal_host_address=os.environ.get('INTERNAL_HOST_ADDRESS',
                                         get_my_primary_local_ipv4()),
)


def parse_args():
    parser = argparse.ArgumentParser("Manage Grafana dashboards")
Exemplo n.º 11
0
def parse_args():
    parser = argparse.ArgumentParser()

    _help = ('Path to voltha.yml config file (default: %s). '
             'If relative, it is relative to main.py of voltha.'
             % defs['config'])
    parser.add_argument('-c', '--config',
                        dest='config',
                        action='store',
                        default=defs['config'],
                        help=_help)

    _help = '<hostname>:<port> to consul agent (default: %s)' % defs['consul']
    parser.add_argument(
        '-C', '--consul', dest='consul', action='store',
        default=defs['consul'],
        help=_help)

    _help = '<hostname>:<port> to etcd server (default: %s)' % defs['etcd']
    parser.add_argument(
        '-e', '--etcd', dest='etcd', action='store',
        default=defs['etcd'],
        help=_help)

    _help = ('<inter_core_subnet> is the subnet connecting all the voltha '
             'instances in a cluster (default: %s)' % defs['inter_core_subnet'])
    parser.add_argument('-V', '--inter-core-subnet',
                        dest='inter_core_subnet',
                        action='store',
                        default=defs['inter_core_subnet'],
                        help=_help)

    _help = ('<pon subnet> is the subnet connecting the voltha instances'
             'with the PON network (default: %s)' % defs['pon_subnet'])
    parser.add_argument('-P', '--pon-subnet',
                        dest='pon_subnet',
                        action='store',
                        default=defs['pon_subnet'],
                        help=_help)

    _help = ('<hostname> or <ip> at which Voltha is reachable from outside '
             'the cluster (default: %s)' % defs['external_host_address'])
    parser.add_argument('-E', '--external-host-address',
                        dest='external_host_address',
                        action='store',
                        default=defs['external_host_address'],
                        help=_help)

    _help = ('port number of the GRPC service exposed by voltha (default: %s)'
             % defs['grpc_port'])
    parser.add_argument('-g', '--grpc-port',
                        dest='grpc_port',
                        action='store',
                        default=defs['grpc_port'],
                        help=_help)

    _help = ('<hostname>:<port> to fluentd server (default: %s). (If not '
             'specified (None), the address from the config file is used'
             % defs['fluentd'])
    parser.add_argument('-F', '--fluentd',
                        dest='fluentd',
                        action='store',
                        default=defs['fluentd'],
                        help=_help)

    _help = ('<hostname> or <ip> at which Voltha is reachable from inside the'
             'cluster (default: %s)' % defs['internal_host_address'])
    parser.add_argument('-H', '--internal-host-address',
                        dest='internal_host_address',
                        action='store',
                        default=defs['internal_host_address'],
                        help=_help)

    _help = ('unique string id of this voltha instance (default: %s)'
             % defs['instance_id'])
    parser.add_argument('-i', '--instance-id',
                        dest='instance_id',
                        action='store',
                        default=defs['instance_id'],
                        help=_help)

    _help = 'ETH interface to recieve (default: %s)' % defs['interface']
    parser.add_argument('-I', '--interface',
                        dest='interface',
                        action='store',
                        default=defs['interface'],
                        help=_help)

    _help = 'open ssh manhole at given port'
    parser.add_argument('-m', '--manhole-port',
                        dest='manhole_port',
                        action='store',
                        type=int,
                        default=None,
                        help=_help)

    _help = 'omit startup banner log lines'
    parser.add_argument('-n', '--no-banner',
                        dest='no_banner',
                        action='store_true',
                        default=False,
                        help=_help)

    _help = 'do not emit periodic heartbeat log messages'
    parser.add_argument('-N', '--no-heartbeat',
                        dest='no_heartbeat',
                        action='store_true',
                        default=False,
                        help=_help)

    _help = ('port number for the rest service (default: %d)'
             % defs['rest_port'])
    parser.add_argument('-R', '--rest-port',
                        dest='rest_port',
                        action='store',
                        type=int,
                        default=defs['rest_port'],
                        help=_help)

    _help = "suppress debug and info logs"
    parser.add_argument('-q', '--quiet',
                        dest='quiet',
                        action='count',
                        help=_help)

    _help = 'enable verbose logging'
    parser.add_argument('-v', '--verbose',
                        dest='verbose',
                        action='count',
                        help=_help)

    _help = ('use docker container name as voltha instance id'
             ' (overrides -i/--instance-id option)')
    parser.add_argument('--instance-id-is-container-name',
                        dest='instance_id_is_container_name',
                        action='store_true',
                        default=False,
                        help=_help)

    _help = ('<hostname>:<port> of the kafka broker (default: %s). (If not '
             'specified (None), the address from the config file is used'
             % defs['kafka'])
    parser.add_argument('-K', '--kafka',
                        dest='kafka',
                        action='store',
                        default=defs['kafka'],
                        help=_help)

    _help = 'backend to use for config persitence'
    parser.add_argument('-b', '--backend',
                        default=defs['backend'],
                        choices=['none', 'consul', 'etcd'],
                        help=_help)

    args = parser.parse_args()

    # post-processing

    if args.instance_id_is_container_name:
        args.instance_id = get_my_containers_name()

    """ 
    The container external, internal IP and PON interface needs to be 
    set based on the subnet data.  At this time the internal IP is not used. 
    The external IP is used for inter-core communications.  If the subnets are
    set then they take precedence over the other relevant arguments (
    external and internal host as well as interface
    """
    if args.inter_core_subnet:
        m_ip = get_my_primary_local_ipv4(inter_core_subnet=args.inter_core_subnet)
        args.external_host_address = m_ip
        args.internal_host_address = m_ip

    if args.pon_subnet:
        args.interface = get_my_primary_interface(args.pon_subnet)

    return args