| 1774 | |
| 1775 | private: |
| 1776 | Status AttachTc(bess::TrafficClass* c_, const bess::pb::TrafficClass& class_, |
| 1777 | EmptyResponse* response) { |
| 1778 | std::unique_ptr<bess::TrafficClass> c(c_); |
| 1779 | int wid = class_.wid(); |
| 1780 | |
| 1781 | if (class_.parent() == "") { |
| 1782 | if (wid != Worker::kAnyWorker && |
| 1783 | (wid < 0 || wid >= Worker::kMaxWorkers)) { |
| 1784 | return return_with_error(response, EINVAL, |
| 1785 | "'wid' must be %d or between 0 and %d", |
| 1786 | Worker::kAnyWorker, Worker::kMaxWorkers - 1); |
| 1787 | } |
| 1788 | |
| 1789 | if ((wid != Worker::kAnyWorker && !is_worker_active(wid)) || |
| 1790 | (wid == Worker::kAnyWorker && num_workers == 0)) { |
| 1791 | if (num_workers == 0 && (wid == 0 || wid == Worker::kAnyWorker)) { |
| 1792 | launch_worker(0, FLAGS_c); |
| 1793 | } else { |
| 1794 | return return_with_error(response, EINVAL, "worker:%d does not exist", |
| 1795 | wid); |
| 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | add_tc_to_orphan(c.release(), wid); |
| 1800 | return Status::OK; |
| 1801 | } |
| 1802 | |
| 1803 | if (wid != Worker::kAnyWorker) { |
| 1804 | return return_with_error(response, EINVAL, |
| 1805 | "Both 'parent' and 'wid'" |
| 1806 | "have been specified"); |
| 1807 | } |
| 1808 | |
| 1809 | bess::TrafficClass* parent; |
| 1810 | const auto& tcs = TrafficClassBuilder::all_tcs(); |
| 1811 | const auto& it = tcs.find(class_.parent()); |
| 1812 | if (it == tcs.end()) { |
| 1813 | return return_with_error(response, ENOENT, "Parent TC '%s' not found", |
| 1814 | class_.parent().c_str()); |
| 1815 | } |
| 1816 | parent = it->second; |
| 1817 | |
| 1818 | bool fail = false; |
| 1819 | switch (parent->policy()) { |
| 1820 | case bess::POLICY_PRIORITY: { |
| 1821 | if (class_.arg_case() != bess::pb::TrafficClass::kPriority) { |
| 1822 | return return_with_error(response, EINVAL, "No priority specified"); |
| 1823 | } |
| 1824 | bess::priority_t pri = class_.priority(); |
| 1825 | if (pri == DEFAULT_PRIORITY) { |
| 1826 | return return_with_error(response, EINVAL, "Priority %d is reserved", |
| 1827 | DEFAULT_PRIORITY); |
| 1828 | } |
| 1829 | fail = !static_cast<bess::PriorityTrafficClass*>(parent)->AddChild( |
| 1830 | c.get(), pri); |
| 1831 | break; |
| 1832 | } |
| 1833 | case bess::POLICY_WEIGHTED_FAIR: |
nothing calls this directly
no test coverage detected