|
Packit |
857059 |
// core API
|
|
Packit |
857059 |
#include <opamgt/opamgt.h>
|
|
Packit |
857059 |
// extensions for SA queries
|
|
Packit |
857059 |
#include <opamgt/opamgt_sa.h>
|
|
Packit |
857059 |
|
|
Packit |
857059 |
int main(int argc, char ** argv)
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
OMGT_STATUS_T status = OMGT_STATUS_SUCCESS;
|
|
Packit |
857059 |
int exitcode = 0;
|
|
Packit |
857059 |
int i;
|
|
Packit |
857059 |
struct omgt_port * port = NULL;
|
|
Packit |
857059 |
int num_records;
|
|
Packit |
857059 |
STL_PORTINFO_RECORD *pi_records = NULL;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
|
|
Packit |
857059 |
// create a session
|
|
Packit |
857059 |
status = omgt_open_port_by_num(&port, 1 /* hfi */, 1 /* port */, NULL);
|
|
Packit |
857059 |
if (OMGT_STATUS_SUCCESS != status) {
|
|
Packit |
857059 |
fprintf(stderr, "failed to open port\n");
|
|
Packit |
857059 |
exitcode=1;
|
|
Packit |
857059 |
goto fail1;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
|
|
Packit |
857059 |
// specify how and what we want to query by
|
|
Packit |
857059 |
omgt_sa_selector_t selector;
|
|
Packit |
857059 |
selector.InputType = InputTypeLid;
|
|
Packit |
857059 |
selector.InputValue.PortInfoRecord.Lid = 1;
|
|
Packit |
857059 |
|
|
Packit |
857059 |
// execute query synchronously
|
|
Packit |
857059 |
status = omgt_sa_get_portinfo_records(port, &selector, &num_records, &pi_records);
|
|
Packit |
857059 |
if (status != OMGT_STATUS_SUCCESS) {
|
|
Packit |
857059 |
exitcode=1;
|
|
Packit |
857059 |
fprintf(stderr, "failed to execute query. MadStatus=0x%x\n", omgt_get_sa_mad_status(port));
|
|
Packit |
857059 |
goto fail2;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if (!num_records) {
|
|
Packit |
857059 |
// we can check result count independent of result type
|
|
Packit |
857059 |
printf("No records found.\n");
|
|
Packit |
857059 |
} else {
|
|
Packit |
857059 |
for (i = 0; i < num_records; ++i) {
|
|
Packit |
857059 |
// the result is a set of SA records, which often follow a pattern
|
|
Packit |
857059 |
// of including a RID section containing top-level identification of
|
|
Packit |
857059 |
// the record, and an encapsulated SM payload.
|
|
Packit |
857059 |
//
|
|
Packit |
857059 |
// in this case:
|
|
Packit |
857059 |
// r->RID: contains the LID and port number as record identifiers
|
|
Packit |
857059 |
// r->PortInfo: the encapsulated subnet management structure (STL_PORT_INFO)
|
|
Packit |
857059 |
STL_PORTINFO_RECORD * r = &pi_records[i]; // sa
|
|
Packit |
857059 |
printf("PortNum: %2u PortLID: 0x%08x\n", r->RID.PortNum, r->RID.EndPortLID);
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
fail2:
|
|
Packit |
857059 |
// free our result buffer...
|
|
Packit |
857059 |
if (pi_records) omgt_sa_free_records(pi_records);
|
|
Packit |
857059 |
// ...and close our session
|
|
Packit |
857059 |
omgt_close_port(port);
|
|
Packit |
857059 |
fail1:
|
|
Packit |
857059 |
return exitcode;
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|