Skip to content

Commit 4bfe426

Browse files
committed
Simics:eth1 IP configuration based on bmc_position
Simics skiboard model connected BMC0's eth1 and BMC1's eth1 interface for simulating redundant BMC internal network. This commit assigns unique IP address on eth1 ip address based on bmc_position uboot environment variable. Tested By: Verified this commit skiboards simics IP address assigned on eth1 based on bmc position uboot variable Signed-off-by: Ravi Teja <[email protected]>
1 parent 04c33fc commit 4bfe426

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/ethernet_interface.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,51 @@ static void writeUpdatedTime(const Manager& manager,
10131013
}
10141014
}
10151015

1016+
size_t getBMCPosition()
1017+
{
1018+
size_t bmcPosition = 0;
1019+
1020+
// NOTE: This a temporary solution for simulation until the
1021+
// daemon that should be providing this information is in place.
1022+
1023+
// Read it out of the bmc_position uboot environment variable
1024+
// This was written by a simulation script.
1025+
std::string cmd{"/sbin/fw_printenv -n bmc_position"};
1026+
1027+
// NOLINTBEGIN(cert-env33-c)
1028+
FILE* pipe = popen(cmd.c_str(), "r");
1029+
// NOLINTEND(cert-env33-c)
1030+
if (pipe == nullptr)
1031+
{
1032+
throw std::runtime_error("Error calling popen to get bmc_position");
1033+
}
1034+
1035+
std::string output;
1036+
std::array<char, 128> buffer;
1037+
while (fgets(buffer.data(), buffer.size(), pipe) != nullptr)
1038+
{
1039+
output.append(buffer.data());
1040+
}
1041+
1042+
int rc = pclose(pipe);
1043+
if (WEXITSTATUS(rc) != 0)
1044+
{
1045+
throw std::runtime_error{std::format(
1046+
"Error running cmd: {}, output = {}, rc = {}", cmd, output, rc)};
1047+
}
1048+
1049+
auto [_,
1050+
ec] = std::from_chars(&*output.begin(), &*output.end(), bmcPosition);
1051+
if (ec != std::errc())
1052+
{
1053+
throw std::runtime_error{
1054+
std::format("Could not extract position from {}: rc {}", output,
1055+
std::to_underlying(ec))};
1056+
}
1057+
1058+
return bmcPosition;
1059+
}
1060+
10161061
void EthernetInterface::writeConfigurationFile()
10171062
{
10181063
config::Parser config;
@@ -1087,6 +1132,24 @@ void EthernetInterface::writeConfigurationFile()
10871132
}
10881133
}
10891134
}
1135+
1136+
// NOTE: This a temporary solution for simulation until the
1137+
// daemon that should be providing this information is in place.
1138+
1139+
// Simics skiboard model connected BMC0's eth1 and BMC1's eth1
1140+
// interface for simulating redundant BMC internal network.
1141+
size_t bmcPosition = getBMCPosition();
1142+
if (interfaceName() == "eth1")
1143+
{
1144+
if (bmcPosition == 1)
1145+
{
1146+
address.emplace_back("9.6.28.101/24");
1147+
}
1148+
else if (bmcPosition == 0)
1149+
{
1150+
address.emplace_back("9.6.28.100/24");
1151+
}
1152+
}
10901153
}
10911154
{
10921155
if (!dhcp4())

0 commit comments

Comments
 (0)