Esempio n. 1
0
    def do_disable(self, line):
        """
        Disable a device. ID of the device needs to be provided
        """
        device_id = line
        if device_id not in self.device_ids():
            self.poutput('Error: There is no such device')
            return
        try:
            stub = self.get_stub()
            device = stub.GetDevice(voltha_pb2.ID(id=device_id))
            if device.admin_state == voltha_pb2.AdminState.DISABLED:
                self.poutput('Error: Device is already disabled')
                return
            stub.DisableDevice(voltha_pb2.ID(id=device_id))
            self.poutput('disabling {}'.format(device_id))

            # Do device query and verify that the device admin status is
            # DISABLED and Operational Status is unknown
            device = stub.GetDevice(voltha_pb2.ID(id=device_id))
            if device.admin_state == voltha_pb2.AdminState.DISABLED:
                self.poutput('disabled successfully {}'.format(device_id))
            else:
                self.poutput('disabling failed {}.  Admin State:{} '
                             'Operation State: {}'.format(device_id,
                                                          device.admin_state,
                                                          device.oper_status))
        except Exception as e:
            self.poutput('Error disabling {}.  Error:{}'.format(device_id, e))
Esempio n. 2
0
    def do_enable(self, line):
        """
        Enable a device. If the <id> is not provided, it will be on the last
        pre-provisioned device.
        """
        device_id = line or self.default_device_id
        self.poutput('enabling {}'.format(device_id))
        try:
            stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
            stub.EnableDevice(voltha_pb2.ID(id=device_id))

            while True:
                device = stub.GetDevice(voltha_pb2.ID(id=device_id))
                # If this is an OLT then acquire logical device id
                if device.oper_status == voltha_pb2.OperStatus.ACTIVE:
                    if device.type.endswith('_olt'):
                        assert device.parent_id
                        self.default_logical_device_id = device.parent_id
                        self.poutput('success (logical device id = {})'.format(
                            self.default_logical_device_id))
                    else:
                        self.poutput('success (device id = {})'.format(
                            device.id))
                    break
                self.poutput('waiting for device to be enabled...')
                sleep(.5)
        except Exception, e:
            self.poutput('Error enabling {}.  Error:{}'.format(device_id, e))
Esempio n. 3
0
    def do_enable(self, line):
        """
        Enable a device. If the <id> is not provided, it will be on the last
        pre-provisioned device.
        """
        device_id = line or self.default_device_id
        if device_id not in self.device_ids():
            self.poutput('Error: There is no such preprovisioned device')
            return

        try:
            stub = self.get_stub()
            device = stub.GetDevice(voltha_pb2.ID(id=device_id))
            if device.admin_state == voltha_pb2.AdminState.ENABLED:
                self.poutput('Error: Device is already enabled')
                return
            stub.EnableDevice(voltha_pb2.ID(id=device_id))
            self.poutput('enabling {}'.format(device_id))

            while True:
                device = stub.GetDevice(voltha_pb2.ID(id=device_id))
                # If this is an OLT then acquire logical device id
                if device.oper_status == voltha_pb2.OperStatus.ACTIVE:
                    if device.type.endswith('_olt'):
                        assert device.parent_id
                        self.default_logical_device_id = device.parent_id
                        self.poutput('success (logical device id = {})'.format(
                            self.default_logical_device_id))
                    else:
                        self.poutput('success (device id = {})'.format(device.id))
                    break
                self.poutput('waiting for device to be enabled...')
                sleep(.5)
        except Exception as e:
            self.poutput('Error enabling {}.  Error:{}'.format(device_id, e))
Esempio n. 4
0
 def _delete_device_grpc(self, stub, device_id):
     try:
         stub.DeleteDevice(voltha_pb2.ID(id=device_id))
         while True:
             device = stub.GetDevice(voltha_pb2.ID(id=device_id))
             assert not device
     except Exception, e:
         self.pt('deleting device {}.  Error:{}'.format(device_id, e))
Esempio n. 5
0
    def do_delete(self, line, opts):
        if not opts.filter_id:
            self.poutput(self.colorize('Error: ', 'red') + 'Specify ' + \
                         self.colorize(self.colorize('"filter id"', 'blue'),
                                       'bold') + ' to update')
            return

        stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
        stub.DeleteAlarmFilter(voltha_pb2.ID(id=opts.filter_id))
Esempio n. 6
0
    def get_device_mib(self, device_id, depth=-1):
        stub = self.get_stub()

        try:
            res = stub.GetMibDeviceData(voltha_pb2.ID(id=device_id),
                                        metadata=(('get-depth', str(depth)), ))
        except Exception as _e:
            res = None

        return res
Esempio n. 7
0
 def _enable_device_grpc(self, stub, device_id):
     logical_device_id = None
     try:
         stub.EnableDevice(voltha_pb2.ID(id=device_id))
         while True:
             device = stub.GetDevice(voltha_pb2.ID(id=device_id))
             # If this is an OLT then acquire logical device id
             if device.oper_status == voltha_pb2.OperStatus.ACTIVE:
                 if device.type.endswith('_olt'):
                     assert device.parent_id
                     logical_device_id = device.parent_id
                     self.pt('success (logical device id = {})'.format(
                         logical_device_id))
                 else:
                     self.pt('success (device id = {})'.format(device.id))
                 break
             self.pt('waiting for device to be enabled...')
             sleep(.5)
     except Exception, e:
         self.pt('Error enabling {}.  Error:{}'.format(device_id, e))
Esempio n. 8
0
 def do_reboot(self, line):
     """
     Rebooting a device. ID of the device needs to be provided
     """
     device_id = line or self.default_device_id
     self.poutput('rebooting {}'.format(device_id))
     try:
         stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
         stub.RebootDevice(voltha_pb2.ID(id=device_id))
         self.poutput('rebooted {}'.format(device_id))
     except Exception, e:
         self.poutput('Error rebooting {}.  Error:{}'.format(device_id, e))
Esempio n. 9
0
    def do_show(self, line, opts):
        stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())

        if not opts.filter_id:
            result = stub.ListAlarmFilters(Empty())
            print_pb_list_as_table("Alarm Filters:", result.filters, {},
                                   self.poutput)
        else:
            result = stub.GetAlarmFilter(voltha_pb2.ID(id=opts.filter_id))
            print_pb_list_as_table(
                "Rules for Filter ID = {}:".format(opts.filter_id),
                result.rules, {}, self.poutput)
Esempio n. 10
0
    def do_activate_olt(self, line):
        """
        Activate an OLT. If the <id> is not provided, it will be on the last
        pre-provisioned OLT.
        """
        device_id = line or self.default_device_id
        self.poutput('activating {}'.format(device_id))
        stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
        stub.ActivateDevice(voltha_pb2.ID(id=device_id))

        # try to acquire logical device id
        while True:
            device = stub.GetDevice(voltha_pb2.ID(id=device_id))
            if device.oper_status == voltha_pb2.OperStatus.ACTIVE:
                assert device.parent_id
                self.default_logical_device_id = device.parent_id
                break
            self.poutput('waiting for device to be activated...')
            sleep(.5)
        self.poutput('success (logical device id = {})'.format(
            self.default_logical_device_id))
Esempio n. 11
0
 def do_delete(self, line):
     """
     Deleting a device. ID of the device needs to be provided
     """
     device_id = line or self.default_device_id
     self.poutput('deleting {}'.format(device_id))
     try:
         stub = self.get_stub()
         stub.DeleteDevice(voltha_pb2.ID(id=device_id))
         self.poutput('deleted {}'.format(device_id))
     except Exception as e:
         self.poutput('Error deleting {}.  Error:{}'.format(device_id, e))
Esempio n. 12
0
 def do_self_test(self, line):
     """
     Self Test a device. ID of the device needs to be provided
     """
     device_id = line or self.default_device_id
     self.poutput('Self Testing {}'.format(device_id))
     try:
         stub = self.get_stub()
         res = stub.SelfTest(voltha_pb2.ID(id=device_id))
         self.poutput('Self Tested {}'.format(device_id))
         self.poutput(dumps(pb2dict(res), indent=4))
     except Exception as e:
         self.poutput('Error in self test {}.  Error:{}'.format(device_id, e))
Esempio n. 13
0
 def do_img_dnld_list(self, line):
     """
     List all image download records for a given device
     """
     device = self.get_device(depth=-1)
     device_id = device.id
     self.poutput('Get all img dnld records {}'.format(device_id))
     try:
         stub = self.get_stub()
         img_dnlds = stub.ListImageDownloads(voltha_pb2.ID(id=device_id))
     except Exception, e:
         self.poutput('Error list img dnlds {}.  Error:{}'.format(device_id, e))
         return
Esempio n. 14
0
 def do_xpon(self, line):
     """xpon <optional> [device_ID] - Enter xpon level command mode"""
     device_id = line.strip()
     if device_id:
         stub = self.get_stub()
         try:
             res = stub.GetDevice(voltha_pb2.ID(id=device_id))
         except Exception:
             self.poutput(
                 self.colorize('Error: ', 'red') + 'No device id ' +
                 self.colorize(device_id, 'blue') + ' is found')
             return
     sub = XponCli(self.get_channel, device_id)
     sub.cmdloop()
Esempio n. 15
0
    def do_disable(self, line):
        """
        Disable a device. ID of the device needs to be provided
        """
        device_id = line
        self.poutput('disabling {}'.format(device_id))
        try:
            stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
            stub.DisableDevice(voltha_pb2.ID(id=device_id))

            # Do device query and verify that the device admin status is
            # DISABLED and Operational Status is unknown
            device = stub.GetDevice(voltha_pb2.ID(id=device_id))
            if device.oper_status == voltha_pb2.OperStatus.UNKNOWN and \
                            device.admin_state == voltha_pb2.AdminState.DISABLED:
                self.poutput('disabled successfully {}'.format(device_id))
            else:
                self.poutput('disabling failed {}.  Admin State:{} '
                             'Operation State: {}'.format(
                                 device_id, device.admin_state,
                                 device.oper_status))
        except Exception, e:
            self.poutput('Error disabling {}.  Error:{}'.format(device_id, e))
Esempio n. 16
0
 def _get_xpon_object_grpc(self, stub, obj_type, device_id=None):
     if obj_type["type"] == "channel_groups":
         res = stub.GetAllChannelgroupConfig(Empty())
     elif obj_type["type"] == "channel_partitions":
         res = stub.GetAllChannelpartitionConfig(Empty())
     elif obj_type["type"] == "channel_pairs":
         res = stub.GetAllChannelpairConfig(Empty())
     elif obj_type["type"] == "channel_terminations":
         res = stub.GetAllChannelterminationConfig(
             voltha_pb2.ID(id=device_id))
     elif obj_type["type"] == "v_ont_anis":
         res = stub.GetAllVOntaniConfig(Empty())
     elif obj_type["type"] == "ont_anis":
         res = stub.GetAllOntaniConfig(Empty())
     elif obj_type["type"] == "v_enets":
         res = stub.GetAllVEnetConfig(Empty())
     return res
Esempio n. 17
0
 def get_logical_ports(self, logical_device_id):
     """
     Return the NNI port number and the first usable UNI port of logical
     device, and the vlan associated with the latter.
     """
     stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
     ports = stub.ListLogicalDevicePorts(
         voltha_pb2.ID(id=logical_device_id)).items
     nni = uni = vlan = None
     for port in ports:
         if nni is None and port.root_port:
             nni = port.ofp_port.port_no
         if uni is None and not port.root_port:
             uni = port.ofp_port.port_no
             uni_device = self.get_device(port.device_id)
             vlan = uni_device.vlan
         if nni is not None and uni is not None:
             return nni, uni, vlan
     raise Exception('No valid port pair found (no ONUs yet?)')
Esempio n. 18
0
    def _get_logical_ports(self, stub, logical_device_id):
        """
        Return the NNI port number and the first usable UNI port of logical
        device, and the vlan associated with the latter.
        """
        ports = stub.ListLogicalDevicePorts(
            voltha_pb2.ID(id=logical_device_id)).items
        nni = None
        unis = []
        for port in ports:
            if port.root_port:
                assert nni is None, "There shall be only one root port"
                nni = port.ofp_port.port_no
            else:
                uni = port.ofp_port.port_no
                uni_device = self._get_device_grpc(stub, port.device_id)
                vlan = uni_device.vlan
                unis.append((uni, vlan))

        assert nni is not None, "No NNI port found"
        assert unis, "Not a single UNI?"

        return nni, unis
Esempio n. 19
0
 def _get_xpon_object_grpc(self, stub, obj_type, device_id=None):
     if obj_type["type"] == "channel_groups":
         res = stub.GetAllChannelgroupConfig(Empty())
     elif obj_type["type"] == "channel_partitions":
         res = stub.GetAllChannelpartitionConfig(Empty())
     elif obj_type["type"] == "channel_pairs":
         res = stub.GetAllChannelpairConfig(Empty())
     elif obj_type["type"] == "channel_terminations":
         res = stub.GetAllChannelterminationConfig(
             voltha_pb2.ID(id=device_id))
     elif obj_type["type"] == "v_ont_anis":
         res = stub.GetAllVOntaniConfig(Empty())
     elif obj_type["type"] == "ont_anis":
         res = stub.GetAllOntaniConfig(Empty())
     elif obj_type["type"] == "v_enets":
         res = stub.GetAllVEnetConfig(Empty())
     elif obj_type["type"] == "gemports":
         res = stub.GetAllGemportsConfigData(Empty())
     elif obj_type["type"] == "tconts":
         res = stub.GetAllTcontsConfigData(Empty())
     elif obj_type["type"] == "traffic_descriptor_profiles":
         res = stub.GetAllTrafficDescriptorProfileData(Empty())
     return res
Esempio n. 20
0
    def get_logical_ports_and_onu_ids(self, logical_device_id):
        """
        Return the NNI port number and the first usable UNI port of logical
        device, and the vlan associated with the latter.
        """
        stub = self.get_stub()
        ports = stub.ListLogicalDevicePorts(
            voltha_pb2.ID(id=logical_device_id)).items
        nni = None
        unis = []
        for port in ports:
            if port.root_port:
                assert nni is None, "There shall be only one root port"
                nni = port.ofp_port.port_no
            else:
                uni_port = port.ofp_port.port_no
                uni_device = self.get_device(port.device_id)
                onu_id = uni_device.proxy_address.onu_id
                unis.append((uni_port, onu_id))

        assert nni is not None, "No NNI port found"
        assert unis, "Not a single UNI?"

        return nni, unis
Esempio n. 21
0
 def get_device(self, depth=0):
     stub = self.get_stub()
     res = stub.GetDevice(voltha_pb2.ID(id=self.device_id),
                          metadata=(('get-depth', str(depth)), ))
     return res
Esempio n. 22
0
 def get_device(self, id):
     stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
     return stub.GetDevice(voltha_pb2.ID(id=id))
Esempio n. 23
0
 def get_device(self, id):
     stub = self.get_stub()
     return stub.GetDevice(voltha_pb2.ID(id=id))
Esempio n. 24
0
 def get_device(self, depth=0):
     stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
     res = stub.GetDevice(voltha_pb2.ID(id=self.device_id),
                          metadata=(('get-depth', str(depth)), ))
     return res
Esempio n. 25
0
 def _get_alarm_filter_grpc(self, stub, alarm_filter_id):
     res = stub.GetAlarmFilter(voltha_pb2.ID(id=alarm_filter_id))
     return res
Esempio n. 26
0
 def _get_device_grpc(self, stub, device_id, depth=0):
     res = stub.GetDevice(voltha_pb2.ID(id=device_id),
                          metadata=(('get-depth', str(depth)), ))
     return res
Esempio n. 27
0
 def _get_olt_flows_grpc(self, stub, logical_device_id):
     res = stub.ListLogicalDeviceFlows(voltha_pb2.ID(id=logical_device_id))
     return res