def _rebuild_tc_class_range(context, qos):
        LOG.debug("Rebuilding tc class range for qos: %s", qos.id)
        used_classes = sorted(
            [1, 65534] +
            [queue.tc_class for queue in qos.queues
             if queue.tc_class is not None])
        for index in range(len(used_classes) - 1):
            if used_classes[index] + 1 < used_classes[index + 1]:
                tc_class_range = QosTcClassRange(
                    qos_id=qos.id,
                    first=used_classes[index] + 1,
                    last=used_classes[index+1] - 1)
                context.session.add(tc_class_range)