Skip to content

Commit 0044e3a

Browse files
shiva-mentameta-codesync[bot]
authored andcommitted
Add new getPortStates Thrift API for Port Manager Mode (portNames->portStates)
Summary: as titled, makes it easier to implement D90685862. Reviewed By: birdsoup Differential Revision: D90710424 fbshipit-source-id: 0095caa1cd3e9528181aa2a457f576e9aeb2bdae
1 parent b595126 commit 0044e3a

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

fboss/qsfp_service/PortManager.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,12 +2199,37 @@ phy::PortPrbsState PortManager::getXphyPortPrbs(
21992199
void PortManager::getPortStates(
22002200
std::map<int32_t, PortStateMachineState>& states,
22012201
std::unique_ptr<std::vector<int32_t>> ids) {
2202+
if (ids->empty()) {
2203+
for (const auto& [_, portId] : portNameToPortID_) {
2204+
ids->push_back(portId);
2205+
}
2206+
}
2207+
22022208
for (const auto& id : *ids) {
22032209
auto portId = PortID(id);
22042210
try {
22052211
states.emplace(id, getPortState(portId));
22062212
} catch (const FbossError& /* e */) {
2207-
XLOG(WARN) << "Unrecognized Port:" << portId;
2213+
XLOG(WARN) << "Unrecognized Port: " << portId;
2214+
}
2215+
}
2216+
}
2217+
2218+
void PortManager::getPortStates(
2219+
std::map<std::string, PortStateMachineState>& states,
2220+
std::unique_ptr<std::vector<std::string>> portNames) {
2221+
if (portNames->empty()) {
2222+
for (const auto& [portNameStr, _] : portNameToPortID_) {
2223+
portNames->push_back(portNameStr);
2224+
}
2225+
}
2226+
2227+
for (const auto& portNameStr : *portNames) {
2228+
try {
2229+
auto portId = getPortIDByPortNameOrThrow(portNameStr);
2230+
states.emplace(portNameStr, getPortState(portId));
2231+
} catch (const FbossError& /* e */) {
2232+
XLOG(WARN) << "Unrecognized Port:" << portNameStr;
22082233
}
22092234
}
22102235
}

fboss/qsfp_service/PortManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ class PortManager {
393393
std::map<int32_t, PortStateMachineState>& states,
394394
std::unique_ptr<std::vector<int32_t>> ids);
395395

396+
void getPortStates(
397+
std::map<std::string, PortStateMachineState>& states,
398+
std::unique_ptr<std::vector<std::string>> portNames);
399+
396400
virtual void initExternalPhyMap(bool forceWarmboot = false);
397401

398402
protected:

fboss/qsfp_service/QsfpServiceHandler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ void QsfpServiceHandler::getPortStateMachineState(
107107
}
108108
}
109109

110+
void QsfpServiceHandler::getPortStateMachineStateFromPortNames(
111+
std::map<std::string, PortStateMachineState>& info,
112+
std::unique_ptr<std::vector<std::string>> portNames) {
113+
auto log = LOG_THRIFT_CALL(INFO);
114+
if (FLAGS_port_manager_mode) {
115+
// Only populate if port manager mode is enabled.
116+
portManager_->getPortStates(info, std::move(portNames));
117+
}
118+
}
119+
110120
void QsfpServiceHandler::getPortMediaInterface(
111121
std::map<std::string, MediaInterfaceCode>& portMediaInterface) {
112122
auto log = LOG_THRIFT_CALL(INFO);

fboss/qsfp_service/QsfpServiceHandler.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ class QsfpServiceHandler
4949
std::map<int32_t, PortStateMachineState>& info,
5050
std::unique_ptr<std::vector<int32_t>> ids) override;
5151

52+
/*
53+
* Returns all qsfp information for the transceiver
54+
*/
55+
void getPortStateMachineStateFromPortNames(
56+
std::map<std::string, PortStateMachineState>& info,
57+
std::unique_ptr<std::vector<std::string>> portNames) override;
58+
5259
/*
5360
* Returns portName to configured media interface
5461
*/

fboss/qsfp_service/if/BUCK

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ thrift_library(
103103
":transceiver",
104104
":transceiver_validation",
105105
"//fboss/agent:switch_config",
106+
"//thrift/annotation:thrift",
106107
],
107108
)
108109

@@ -133,6 +134,7 @@ thrift_library(
133134
":transceiver",
134135
"//fboss/lib/if:pim_state",
135136
"//fboss/lib/phy:phy",
137+
"//thrift/annotation:thrift",
136138
],
137139
)
138140

@@ -161,6 +163,7 @@ thrift_library(
161163
":transceiver",
162164
"//fboss/agent/hw:hardware_stats",
163165
"//fboss/lib/phy:phy",
166+
"//thrift/annotation:thrift",
164167
],
165168
)
166169

@@ -185,6 +188,9 @@ thrift_library(
185188
thrift_py_options = "json,sort_keys",
186189
thrift_rust_options = "serde",
187190
thrift_srcs = {"port_state.thrift": []},
191+
deps = [
192+
"//thrift/annotation:thrift",
193+
],
188194
)
189195

190196
thrift_library(
@@ -213,5 +219,6 @@ thrift_library(
213219
"//fboss/agent:switch_config",
214220
"//fboss/lib/if:fboss_common",
215221
"//thrift/annotation:cpp",
222+
"//thrift/annotation:thrift",
216223
],
217224
)

fboss/qsfp_service/if/qsfp.thrift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ service QsfpService extends phy.FbossCommonPhyCtrl {
3232
1: list<i32> idx,
3333
) throws (1: fboss.FbossBaseError error);
3434

35+
/*
36+
* Get state information about a port
37+
*/
38+
map<
39+
string,
40+
transceiver.PortStateMachineState
41+
> getPortStateMachineStateFromPortNames(1: list<string> portNames) throws (
42+
1: fboss.FbossBaseError error,
43+
);
44+
3545
/*
3646
* Get config validation status of a transceiver
3747
*/

0 commit comments

Comments
 (0)