Skip to content

Commit 26f203a

Browse files
committed
[alf] Transition to Serial-Endpoint ID scheme for services
1 parent 7c9468d commit 26f203a

File tree

15 files changed

+118
-95
lines changed

15 files changed

+118
-95
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ DIM_DNS_NODE=thedimdns.cern.ch
2020
`
2121

2222
### o2-alf-client
23-
o2-alf-client is the binary of an ALF client used solely for testing purposes. On top of the DIM Nameserver it expects the hostname of the node hosting the ALF server, the card's sequence number and the link number as command-line arguments. Different arguments to test different types of services are available (run with `--help`).
23+
o2-alf-client is the binary of an ALF client used solely for testing purposes. On top of the DIM Nameserver it expects the hostname of the node hosting the ALF server, the card's serial and endpoint, and the link number as command-line arguments. Different arguments to test different types of services are available (run with `--help`).
2424

2525
`
26-
o2-alf-client --dim-dns-node thedimdns.cern.ch --alf-id thealfserver --card-sequence 0 --link 4
26+
o2-alf-client --dim-dns-node thedimdns.cern.ch --alf-id thealfserver --serial 1041 --endpoint 1 --link 4
2727
`
2828

2929
### o2-alf-lib-client
3030
o2-alf-lib-client is the binary of an ALF SC library client used solely for testing purposes. It expects parameters for the SC modules to test, the card and link ID (run with `--help` for the different options).
3131

3232
`
33-
o2-alf-lib-client --card-id=#1 --link-id=0 --swt
33+
o2-alf-lib-client --card-id=#1 --serial=1041 --endpoint=1 --swt
3434
`
3535

3636
## DIM Services
3737

38-
Service names are identified by the server's hostname, the card's sequence number (as reported during ALF's startup) and the link, as follows:
38+
Service names are identified by the server's hostname, the card's serial and endpoint pair and the link, as follows:
3939

4040
`
41-
ALF_[hostname]/SERIAL_[card_sequence_number]/LINK_[link]/[service_name]
41+
ALF_[hostname]/SERIAL_[serial]/ENDPOINT_[endpoint]/LINK_[link]/[service_name]
4242
`
4343

4444
### DIM RPC services

apps/Alf.cxx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class Alf : public AliceO2::Common::Program
8585
AlfServer alfServer = AlfServer();
8686

8787
std::vector<roc::CardDescriptor> cardsFound = roc::findCards();
88-
int cardSequence = -1;
8988
for (auto const& card : cardsFound) {
9089
std::vector<AlfLink> links;
9190

@@ -101,32 +100,29 @@ class Alf : public AliceO2::Common::Program
101100
}
102101
}
103102

104-
cardSequence++;
105-
106103
if (card.cardType == roc::CardType::Cru) {
107104

108-
Logger::get().log() << "CRU #" << cardSequence << " : " << card.pciAddress << endm;
109-
bar = roc::ChannelFactory().getBar(card.pciAddress, 2);
105+
Logger::get().log() << "CRU " << card.serialId << endm;
106+
bar = roc::ChannelFactory().getBar(card.serialId, 2);
110107
for (int linkId = 0; linkId < CRU_NUM_LINKS; linkId++) {
111-
links.push_back({ alfId, cardSequence, linkId, bar, roc::CardType::Cru });
108+
links.push_back({ alfId, card.serialId, linkId, card.serialId.getEndpoint() * 12 + linkId, bar, roc::CardType::Cru });
112109
}
113110

114111
} else if (card.cardType == roc::CardType::Crorc) {
115-
Logger::get().log() << "CRORC #" << cardSequence << " : " << card.pciAddress << endm;
112+
Logger::get().log() << "CRORC " << card.serialId << endm;
116113
for (int linkId = 0; linkId < CRORC_NUM_LINKS; linkId++) {
117-
bar = roc::ChannelFactory().getBar(card.pciAddress, linkId);
118-
links.push_back({ alfId, cardSequence, linkId, bar, roc::CardType::Crorc });
114+
bar = roc::ChannelFactory().getBar(card.serialId, linkId);
115+
links.push_back({ alfId, card.serialId, linkId, -1, bar, roc::CardType::Crorc });
119116
}
120117
} else {
121-
Logger::get().log() << AliceO2::InfoLogger::InfoLogger::Severity::Warning << card.pciAddress << " is not a CRU or a CRORC. Skipping..." << endm;
118+
Logger::get().log() << AliceO2::InfoLogger::InfoLogger::Severity::Warning << card.serialId << " is not a CRU or a CRORC. Skipping..." << endm;
122119
}
123120

124121
if (isVerbose()) {
125122
for (auto const& link : links) {
126-
Logger::get().log() << link.alfId << " " << link.cardSequence << " " << link.linkId << endm;
123+
Logger::get().log() << link.alfId << " " << link.serialId << " " << link.linkId << endm;
127124
}
128125
}
129-
130126
alfServer.makeRpcServers(links);
131127
}
132128

apps/AlfClient.cxx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ class AlfClient : public AliceO2::Common::Program
5050
options.add_options()("dim-dns-node",
5151
po::value<std::string>(&mOptions.dimDnsNode)->default_value(""),
5252
"The DIM DNS node to connect to if the env var is not set");
53-
options.add_options()("card-sequence",
54-
po::value<int>(&mOptions.cardSequence),
55-
"Card sequence number");
53+
options.add_options()("serial",
54+
po::value<int>(&mOptions.serial),
55+
"Card serial number");
56+
options.add_options()("endpoint",
57+
po::value<int>(&mOptions.endpoint),
58+
"Card endpoint");
5659
options.add_options()("link",
5760
po::value<int>(&mOptions.link),
5861
"Link number");
@@ -112,9 +115,9 @@ class AlfClient : public AliceO2::Common::Program
112115
std::string alfId = mOptions.alfId;
113116
boost::to_upper(alfId);
114117

115-
Logger::get().log() << "Starting the DIM Client using ALF ID=" << alfId << ", card #=" << mOptions.cardSequence << " and link=" << mOptions.link << endm;
118+
Logger::get().log() << "Starting the DIM Client using ALF ID=" << alfId << ", card=" << mOptions.serial << ":" << mOptions.endpoint << " and link=" << mOptions.link << endm;
116119

117-
AlfLink link = AlfLink{ alfId, mOptions.cardSequence, mOptions.link, nullptr, roc::CardType::Cru };
120+
AlfLink link = AlfLink{ alfId, roc::SerialId(mOptions.serial, mOptions.endpoint), mOptions.link, mOptions.endpoint * 12 + mOptions.link, nullptr, roc::CardType::Cru };
118121

119122
ServiceNames names(link);
120123

@@ -254,7 +257,8 @@ class AlfClient : public AliceO2::Common::Program
254257
private:
255258
struct OptionsStruct {
256259
std::string dimDnsNode = "";
257-
int cardSequence = -1;
260+
int serial = -1;
261+
int endpoint = 0;
258262
int link = -1;
259263
std::string alfId = "";
260264
bool crorc = false;

apps/AlfLibClient.cxx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@ class AlfLibClient : public AliceO2::Common::Program
5353
options.add_options()("swt",
5454
po::bool_switch(&mOptions.swt)->default_value(false),
5555
"Flag enabling the swt tests");
56-
options.add_options()("id",
57-
po::value<std::string>(&mOptions.cardId)->default_value("-1"),
58-
"Card ID to use");
56+
options.add_options()("serial",
57+
po::value<int>(&mOptions.serial)->default_value(-1),
58+
"Serial to use");
59+
options.add_options()("endpoint",
60+
po::value<int>(&mOptions.endpoint)->default_value(0),
61+
"Endpoint to use");
5962
}
6063

6164
virtual void run(const po::variables_map&) override
6265
{
6366
if (mOptions.sca) {
6467
std::cout << "Running SCA test" << std::endl;
65-
auto sca = Sca(mOptions.cardId, mOptions.link);
68+
auto sca = Sca(roc::SerialId{ mOptions.serial, mOptions.endpoint }, mOptions.link);
6669
sca.reset();
6770

6871
std::cout << "Running simple SCA operation" << std::endl;
@@ -96,7 +99,7 @@ class AlfLibClient : public AliceO2::Common::Program
9699

97100
if (mOptions.swt) {
98101
std::cout << "Running SWT test" << std::endl;
99-
auto swt = Swt(mOptions.cardId, mOptions.link);
102+
auto swt = Swt(roc::SerialId{ mOptions.serial, mOptions.endpoint }, mOptions.link);
100103

101104
std::cout << "Running simple SWT operations" << std::endl;
102105
try {
@@ -116,7 +119,7 @@ class AlfLibClient : public AliceO2::Common::Program
116119

117120
std::cout << "Running an SWT sequence" << std::endl;
118121
std::vector<std::pair<Swt::Operation, Swt::Data>> ops;
119-
swt = Swt(mOptions.cardId);
122+
swt = Swt(roc::SerialId{ mOptions.serial, mOptions.endpoint });
120123
swt.setChannel(1);
121124
ops.push_back({ Swt::Operation::Reset, {} });
122125
ops.push_back({ Swt::Operation::Write, SwtWord{ 0xcafe, 0x41d, 0x0 } });
@@ -150,7 +153,7 @@ class AlfLibClient : public AliceO2::Common::Program
150153

151154
if (mOptions.ic) {
152155
std::cout << "Running IC test" << std::endl;
153-
auto ic = Ic(mOptions.cardId, mOptions.link);
156+
auto ic = Ic(roc::SerialId{ mOptions.serial, mOptions.endpoint }, mOptions.link);
154157
ic.reset();
155158

156159
std::cout << "Running Simple IC operations" << std::endl;
@@ -197,7 +200,8 @@ class AlfLibClient : public AliceO2::Common::Program
197200
bool lla = false;
198201
bool sca = false;
199202
bool swt = false;
200-
std::string cardId = "-1";
203+
int serial = -1;
204+
int endpoint = 0;
201205
} mOptions;
202206
};
203207

include/Alf/Common.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ namespace alf
2828

2929
namespace roc = AliceO2::roc;
3030

31-
static constexpr int CRU_NUM_LINKS(24);
31+
static constexpr int CRU_NUM_LINKS(12);
3232
static constexpr int CRORC_NUM_LINKS(6);
3333

3434
static constexpr auto BUSY_TIMEOUT = std::chrono::milliseconds(10);
3535
static constexpr auto CHANNEL_BUSY_TIMEOUT = std::chrono::milliseconds(10);
3636

3737
struct AlfLink {
3838
std::string alfId;
39-
int cardSequence;
39+
roc::SerialId serialId = { -1, 0 };
4040
int linkId;
41+
int rawLinkId;
4142
std::shared_ptr<roc::BarInterface> bar;
4243
roc::CardType::type cardType;
4344
};

include/Alf/Lla.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ namespace alf
2828
class LlaSession
2929
{
3030
public:
31-
LlaSession(std::string sessionName, int cardId);
31+
LlaSession(std::string sessionName, roc::SerialId serialId);
3232
void start();
3333
void stop();
3434

3535
private:
3636
lla::SessionParameters mParams;
3737
std::unique_ptr<lla::Session> mSession;
3838
std::string mSessionName;
39-
int mCardId;
39+
roc::SerialId mSerialId;
4040
};
4141

4242
} // namespace alf

src/AlfClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ class RegisterSequenceRpc : DimRpcInfoWrapper
158158

159159
std::string write(const std::string& buffer)
160160
{
161-
std::cout << "Setting: " << buffer << std::endl;
162161
setString(buffer);
163162
std::string ret;
164163
try {

src/AlfServer.cxx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,41 +155,41 @@ std::string AlfServer::patternPlayer(const std::string& parameter, std::shared_p
155155
return "";
156156
}
157157

158-
std::string AlfServer::llaSessionStart(const std::string& parameter, int cardId)
158+
std::string AlfServer::llaSessionStart(const std::string& parameter, roc::SerialId serialId)
159159
{
160160
std::vector<std::string> parameters = Util::split(parameter, pairSeparator());
161161
if (parameters.size() < 1 || parameters.size() > 2) {
162162
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("Wrong number of parameters for the LLA Session Start RPC call: " + std::to_string(parameters.size())));
163163
}
164164

165-
if (mSessions.find(cardId) == mSessions.end()) {
165+
if (mSessions.find(serialId) == mSessions.end()) {
166166
lla::SessionParameters params = lla::SessionParameters::makeParameters()
167167
.setSessionName(parameters[0])
168-
.setCardId(roc::PciSequenceNumber(cardId));
169-
mSessions[cardId] = std::make_unique<lla::Session>(params);
168+
.setCardId(serialId);
169+
mSessions[serialId] = std::make_unique<lla::Session>(params);
170170
} /*else {
171171
// TODO: Update session name?
172172
}*/
173173

174174
if (parameters.size() == 2) {
175-
if (!mSessions[cardId]->timedStart(std::stoi(parameters[1]))) {
176-
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("Could not start session for serial " + std::to_string(cardId)));
175+
if (!mSessions[serialId]->timedStart(std::stoi(parameters[1]))) {
176+
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("Could not start session for serial " + serialId.toString()));
177177
}
178178
} else {
179-
if (!mSessions[cardId]->start()) {
180-
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("Could not start session for serial " + std::to_string(cardId)));
179+
if (!mSessions[serialId]->start()) {
180+
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("Could not start session for serial " + serialId.toString()));
181181
}
182182
}
183183
return "";
184184
}
185185

186-
std::string AlfServer::llaSessionStop(const std::string& /*parameter*/, int cardId)
186+
std::string AlfServer::llaSessionStop(const std::string& /*parameter*/, roc::SerialId serialId)
187187
{
188-
if (mSessions.find(cardId) == mSessions.end()) {
189-
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("Session was not started for serial " + std::to_string(cardId)));
188+
if (mSessions.find(serialId) == mSessions.end()) {
189+
BOOST_THROW_EXCEPTION(AlfException() << ErrorInfo::Message("Session was not started for serial " + serialId.toString()));
190190
}
191191

192-
mSessions[cardId]->stop();
192+
mSessions[serialId]->stop();
193193
return "";
194194
}
195195

@@ -510,7 +510,7 @@ std::vector<std::pair<Ic::Operation, Ic::Data>> AlfServer::parseStringToIcPairs(
510510

511511
void AlfServer::makeRpcServers(std::vector<AlfLink> links)
512512
{
513-
for (const auto& link : links) {
513+
for (auto& link : links) {
514514

515515
// Function to create RPC server
516516
auto makeServer = [&](std::string name, auto callback) {
@@ -521,7 +521,7 @@ void AlfServer::makeRpcServers(std::vector<AlfLink> links)
521521
ServiceNames names(link);
522522

523523
// Start the RPC Servers
524-
auto& servers = mRpcServers[link.cardSequence][link.linkId];
524+
auto& servers = mRpcServers[link.serialId][link.linkId];
525525
std::shared_ptr<roc::BarInterface> bar = link.bar;
526526

527527
if (link.cardType == roc::CardType::Cru) {
@@ -539,11 +539,11 @@ void AlfServer::makeRpcServers(std::vector<AlfLink> links)
539539

540540
// LLA Session Start
541541
servers.push_back(makeServer(names.llaSessionStart(),
542-
[link, this](auto parameter) { return llaSessionStart(parameter, link.cardSequence); }));
542+
[link, this](auto parameter) { return llaSessionStart(parameter, link.serialId); }));
543543

544544
// LLA Session Stop
545545
servers.push_back(makeServer(names.llaSessionStop(),
546-
[link, this](auto parameter) { return llaSessionStop(parameter, link.cardSequence); }));
546+
[link, this](auto parameter) { return llaSessionStop(parameter, link.serialId); }));
547547
}
548548

549549
// SCA Sequence

src/AlfServer.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class AlfServer
5555
static std::string icGbtI2cWrite(const std::string& parameter, AlfLink link);
5656
static std::string patternPlayer(const std::string& parameter, std::shared_ptr<roc::BarInterface>);
5757
static std::string registerBlobWrite(const std::string& parameter, AlfLink link);
58-
std::string llaSessionStart(const std::string& parameter, int cardSequence);
59-
std::string llaSessionStop(const std::string& parameter, int cardSequence);
58+
std::string llaSessionStart(const std::string& parameter, roc::SerialId serialId);
59+
std::string llaSessionStop(const std::string& parameter, roc::SerialId serialId);
6060

6161
static std::vector<uint32_t> stringToRegisterPair(const std::string stringPair);
6262
static std::pair<Sca::Operation, Sca::Data> stringToScaPair(const std::string stringPair);
@@ -68,10 +68,14 @@ class AlfServer
6868
static std::vector<std::pair<Ic::Operation, Ic::Data>> parseStringToIcPairs(std::vector<std::string> stringPairs);
6969
static roc::PatternPlayer::Info parseStringToPatternPlayerInfo(const std::vector<std::string> sringsPairs);
7070

71-
/// cardSequence -> link -> vector of RPC servers
72-
std::map<int, std::map<int, std::vector<std::unique_ptr<StringRpcServer>>>> mRpcServers;
71+
// custom comparator for the SerialId keys of the maps
72+
struct serialIdComparator {
73+
bool operator()(const roc::SerialId& a, const roc::SerialId& b) { return a.toString() < b.toString(); };
74+
};
7375

74-
std::map<int, std::unique_ptr<lla::Session>> mSessions;
76+
/// serialId -> link -> vector of RPC servers
77+
std::map<roc::SerialId, std::map<int, std::vector<std::unique_ptr<StringRpcServer>>>, serialIdComparator> mRpcServers;
78+
std::map<roc::SerialId, std::unique_ptr<lla::Session>, serialIdComparator> mSessions;
7579
};
7680

7781
} // namespace alf

src/DimServices/ServiceNames.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ DEFLINKSERVICENAME(icGbtI2cWrite, "IC_GBT_I2C_WRITE")
4848

4949
std::string ServiceNames::formatLink(std::string name) const
5050
{
51-
return ((boost::format("ALF_%1%/SERIAL_%2%/LINK_%3%/%4%") % mAlfId % mCardSequence % mLink % name)).str();
51+
return ((boost::format("ALF_%1%/SERIAL_%2%/ENDPOINT_%3%/LINK_%4%/%5%") % mAlfId % mSerialId.getSerial() % mSerialId.getEndpoint() % mLink % name)).str();
5252
}
5353

5454
std::string ServiceNames::format(std::string name) const
5555
{
56-
return ((boost::format("ALF_%1%/SERIAL_%2%/%3%") % mAlfId % mCardSequence % name)).str();
56+
return ((boost::format("ALF_%1%/SERIAL_%2%/ENDPOINT_%3%/%4%") % mAlfId % mSerialId.getSerial() % mSerialId.getEndpoint() % name)).str();
5757
}
5858

5959
} // namespace alf

0 commit comments

Comments
 (0)