| 1857 | } |
| 1858 | |
| 1859 | bess::TrafficClass* FindTc(const bess::pb::TrafficClass& class_, |
| 1860 | EmptyResponse* response) { |
| 1861 | bess::TrafficClass* c = nullptr; |
| 1862 | |
| 1863 | if (class_.name().length() != 0) { |
| 1864 | const char* name = class_.name().c_str(); |
| 1865 | const auto all_tcs = TrafficClassBuilder::all_tcs(); |
| 1866 | auto it = all_tcs.find(name); |
| 1867 | if (it == all_tcs.end()) { |
| 1868 | return_with_error(response, ENOENT, "Tc '%s' doesn't exist", name); |
| 1869 | return nullptr; |
| 1870 | } |
| 1871 | |
| 1872 | c = it->second; |
| 1873 | } else if (class_.leaf_module_name().length() != 0) { |
| 1874 | const std::string& module_name = class_.leaf_module_name(); |
| 1875 | const auto& it = ModuleGraph::GetAllModules().find(module_name); |
| 1876 | if (it == ModuleGraph::GetAllModules().end()) { |
| 1877 | return_with_error(response, ENOENT, "No module '%s' found", |
| 1878 | module_name.c_str()); |
| 1879 | return nullptr; |
| 1880 | } |
| 1881 | Module* m = it->second; |
| 1882 | |
| 1883 | task_id_t tid = class_.leaf_module_taskid(); |
| 1884 | if (tid >= MAX_TASKS_PER_MODULE) { |
| 1885 | return_with_error(response, EINVAL, "'taskid' must be between 0 and %d", |
| 1886 | MAX_TASKS_PER_MODULE - 1); |
| 1887 | return nullptr; |
| 1888 | } |
| 1889 | |
| 1890 | if (tid >= m->tasks().size()) { |
| 1891 | return_with_error(response, ENOENT, "Task %s:%hu does not exist", |
| 1892 | class_.leaf_module_name().c_str(), tid); |
| 1893 | return nullptr; |
| 1894 | } |
| 1895 | |
| 1896 | c = m->tasks()[tid]->GetTC(); |
| 1897 | } else { |
| 1898 | return_with_error(response, EINVAL, |
| 1899 | "One of 'name' or " |
| 1900 | "'leaf_module_name' must be specified"); |
| 1901 | return nullptr; |
| 1902 | } |
| 1903 | |
| 1904 | if (!c) { |
| 1905 | return_with_error(response, ENOENT, "Error finding TC"); |
| 1906 | } |
| 1907 | |
| 1908 | return c; |
| 1909 | } |
| 1910 | |
| 1911 | // function to call to close this gRPC service. |
| 1912 | std::function<void()> shutdown_func_; |
nothing calls this directly
no test coverage detected