Skip to content

Commit

Permalink
zigbee: Add NWK status operator overload
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Gallegos Ramonet committed Jan 14, 2025
1 parent cd67ed9 commit 6506f44
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 21 deletions.
9 changes: 4 additions & 5 deletions src/zigbee/examples/zigbee-nwk-direct-join.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ NwkDataIndication(Ptr<ZigbeeStack> stack, NldeDataIndicationParams params, Ptr<P
static void
NwkNetworkFormationConfirm(Ptr<ZigbeeStack> stack, NlmeNetworkFormationConfirmParams params)
{
std::cout << "NlmeNetworkFormationConfirmStatus = " << static_cast<uint32_t>(params.m_status)
<< "\n";
std::cout << "NlmeNetworkFormationConfirmStatus = " << params.m_status << "\n";
}

static void
NwkDirectJoinConfirm(Ptr<ZigbeeStack> stack, NlmeDirectJoinConfirmParams params)
{
std::cout << "NlmeDirectJoinConfirmStatus = " << static_cast<uint32_t>(params.m_status) << "\n";
std::cout << "NlmeDirectJoinConfirmStatus = " << params.m_status << "\n";
}

static void
Expand All @@ -79,8 +78,8 @@ NwkJoinConfirm(Ptr<ZigbeeStack> stack, NlmeJoinConfirmParams params)
}
else
{
std::cout << " The device FAILED to join the network with status "
<< static_cast<uint32_t>(params.m_status) << "\n";
std::cout << " The device FAILED to join the network with status " << params.m_status
<< "\n";
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/zigbee/examples/zigbee-nwk-routing-grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ NwkDataIndication(Ptr<ZigbeeStack> stack, NldeDataIndicationParams params, Ptr<P
static void
NwkNetworkFormationConfirm(Ptr<ZigbeeStack> stack, NlmeNetworkFormationConfirmParams params)
{
std::cout << "NlmeNetworkFormationConfirmStatus = " << static_cast<uint32_t>(params.m_status)
<< "\n";
std::cout << "NlmeNetworkFormationConfirmStatus = " << params.m_status << "\n";
}

static void
Expand Down Expand Up @@ -152,8 +151,7 @@ NwkNetworkDiscoveryConfirm(Ptr<ZigbeeStack> stack, NlmeNetworkDiscoveryConfirmPa
}
else
{
std::cout << " WARNING: Unable to discover networks | status: "
<< static_cast<uint32_t>(params.m_status) << "\n";
std::cout << " WARNING: Unable to discover networks | status: " << params.m_status << "\n";
}
}

Expand All @@ -178,16 +176,15 @@ NwkJoinConfirm(Ptr<ZigbeeStack> stack, NlmeJoinConfirmParams params)
else
{
std::cout << Simulator::Now().As(Time::S)
<< " The device FAILED to join the network with status "
<< static_cast<uint32_t>(params.m_status) << "\n";
<< " The device FAILED to join the network with status " << params.m_status
<< "\n";
}
}

static void
NwkRouteDiscoveryConfirm(Ptr<ZigbeeStack> stack, NlmeRouteDiscoveryConfirmParams params)
{
std::cout << "NlmeRouteDiscoveryConfirmStatus = " << static_cast<uint32_t>(params.m_status)
<< "\n";
std::cout << "NlmeRouteDiscoveryConfirmStatus = " << params.m_status << "\n";
}

int
Expand Down
9 changes: 3 additions & 6 deletions src/zigbee/examples/zigbee-nwk-routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ NwkDataIndication(Ptr<ZigbeeStack> stack, NldeDataIndicationParams params, Ptr<P
static void
NwkNetworkFormationConfirm(Ptr<ZigbeeStack> stack, NlmeNetworkFormationConfirmParams params)
{
std::cout << "NlmeNetworkFormationConfirmStatus = " << static_cast<uint32_t>(params.m_status)
<< "\n";
std::cout << "NlmeNetworkFormationConfirmStatus = " << params.m_status << "\n";
}

static void
Expand Down Expand Up @@ -152,8 +151,7 @@ NwkNetworkDiscoveryConfirm(Ptr<ZigbeeStack> stack, NlmeNetworkDiscoveryConfirmPa
}
else
{
NS_ABORT_MSG(
"Unable to discover networks | status: " << static_cast<uint32_t>(params.m_status));
NS_ABORT_MSG("Unable to discover networks | status: " << params.m_status);
}
}

Expand Down Expand Up @@ -185,8 +183,7 @@ NwkJoinConfirm(Ptr<ZigbeeStack> stack, NlmeJoinConfirmParams params)
static void
NwkRouteDiscoveryConfirm(Ptr<ZigbeeStack> stack, NlmeRouteDiscoveryConfirmParams params)
{
std::cout << "NlmeRouteDiscoveryConfirmStatus = " << static_cast<uint32_t>(params.m_status)
<< "\n";
std::cout << "NlmeRouteDiscoveryConfirmStatus = " << params.m_status << "\n";
}

int
Expand Down
171 changes: 171 additions & 0 deletions src/zigbee/model/zigbee-nwk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3093,5 +3093,176 @@ ZigbeeNwk::UpdateBeaconPayload()
m_mac->MlmeSetRequest(MacPibAttributeIdentifier::macBeaconPayload, pibAttr);
}
std::ostream&
operator<<(std::ostream& os, const NwkStatus& state)
{
switch (state)
{
case NwkStatus::SUCCESS:
os << "SUCCESS";
break;
case NwkStatus::FULL_CAPACITY:
os << "FULL CAPACITY";
break;
case NwkStatus::ACCESS_DENIED:
os << "ACCESS DENIED";
break;
case NwkStatus::COUNTER_ERROR:
os << "COUNTER ERROR";
break;
case NwkStatus::IMPROPER_KEY_TYPE:
os << "IMPROPER KEY TYPE";
break;
case NwkStatus::IMPROPER_SECURITY_LEVEL:
os << "IMPROPER SECURITY LEVEL";
break;
case NwkStatus::UNSUPPORTED_LEGACY:
os << "UNSUPPORTED LEGACY";
break;
case NwkStatus::UNSUPPORTED_SECURITY:
os << "UNSUPPORTED SECURITY";
break;
case NwkStatus::BEACON_LOSS:
os << "BEACON LOSS";
break;
case NwkStatus::CHANNEL_ACCESS_FAILURE:
os << "CHANNEL ACCESS FAILURE";
break;
case NwkStatus::DENIED:
os << "DENIED";
break;
case NwkStatus::DISABLE_TRX_FAILURE:
os << "DISABLE TRX FAILURE";
break;
case NwkStatus::SECURITY_ERROR:
os << "SECURITY ERROR";
break;
case NwkStatus::FRAME_TOO_LONG:
os << "FRAME TOO LONG";
break;
case NwkStatus::INVALID_GTS:
os << "INVALID GTS";
break;
case NwkStatus::INVALID_HANDLE:
os << "INVALID HANDLE";
break;
case NwkStatus::NO_ACK:
os << "NO ACKNOLEDGMENT";
break;
case NwkStatus::NO_BEACON:
os << "NO BEACON";
break;
case NwkStatus::NO_DATA:
os << "NO DATA";
break;
case NwkStatus::NO_SHORT_ADDRESS:
os << "NO SHORT ADDRESS";
break;
case NwkStatus::OUT_OF_CAP:
os << "OUT OF CAP";
break;
case NwkStatus::PAN_ID_CONFLICT:
os << "PAN ID CONFLICT";
break;
case NwkStatus::REALIGMENT:
os << "REALIGMENT";
break;
case NwkStatus::TRANSACTION_EXPIRED:
os << "TRANSACTION EXPIRED";
break;
case NwkStatus::TRANSACTION_OVERFLOW:
os << "TRANSACTION OVERFLOW";
break;
case NwkStatus::TX_ACTIVE:
os << "TX ACTIVE";
break;
case NwkStatus::UNAVAILABLE_KEY:
os << "UNAVAILABLE KEY";
break;
case NwkStatus::INVALID_ADDRESS:
os << "INVALID ADDRESS";
break;
case NwkStatus::ON_TIME_TOO_LONG:
os << "ON TIME TOO LONG";
break;
case NwkStatus::PAST_TIME:
os << "PAST TIME";
break;
case NwkStatus::TRACKING_OFF:
os << "TRACKING OFF";
break;
case NwkStatus::INVALID_INDEX:
os << "INVALID INDEX";
break;
case NwkStatus::READ_ONLY:
os << "READ ONLY";
break;
case NwkStatus::SUPERFRAME_OVERLAP:
os << "SUPERFRAME OVERLAP";
break;
case NwkStatus::INVALID_PARAMETER:
os << "INVALID PARAMETER";
break;
case NwkStatus::INVALID_REQUEST:
os << "INVALID REQUEST";
break;
case NwkStatus::NOT_PERMITED:
os << "NO PERMITED";
break;
case NwkStatus::STARTUP_FAILURE:
os << "STARTUP FAILURE";
break;
case NwkStatus::ALREADY_PRESENT:
os << "ALREADY PRESENT";
break;
case NwkStatus::SYNC_FAILURE:
os << "SYNC FAILURE";
break;
case NwkStatus::NEIGHBOR_TABLE_FULL:
os << "NEIGHBOR TABLE FULL";
break;
case NwkStatus::UNKNOWN_DEVICE:
os << "UNKNOWN DEVICE";
break;
case NwkStatus::UNSUPPORTED_ATTRIBUTE:
os << "UNSUPPORTED ATTRIBUTE";
break;
case NwkStatus::NO_NETWORKS:
os << "NO NETWORKS";
break;
case NwkStatus::MAX_FRM_COUNTER:
os << "MAX FRAME COUNTER";
break;
case NwkStatus::NO_KEY:
os << "NO KEY";
break;
case NwkStatus::BAD_CCM_OUTPUT:
os << "BAD CCM OUTPUT";
break;
case NwkStatus::ROUTE_DISCOVERY_FAILED:
os << "ROUTE DISCOVERY FAILED";
break;
case NwkStatus::ROUTE_ERROR:
os << "ROUTE ERROR";
break;
case NwkStatus::BT_TABLE_FULL:
os << "BT TABLE FULL";
break;
case NwkStatus::FRAME_NOT_BUFFERED:
os << "FRAME NOT BUFFERED";
break;
case NwkStatus::INVALID_INTERFACE:
os << "INVALID INTERFACE";
break;
case NwkStatus::LIMIT_REACHED:
os << "LIMIT REACHED";
break;
case NwkStatus::SCAN_IN_PROGRESS:
os << "SCAN IN PROGRESS";
break;
}
return os;
}
} // namespace zigbee
} // namespace ns3
9 changes: 9 additions & 0 deletions src/zigbee/model/zigbee-nwk.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ enum NwkStatus : std::uint8_t
SCAN_IN_PROGRESS = 0xd7 //!< The dev was scanning during this call (IEEE 802.5.4)
};

/**
* Overloaded operator to print the value of a NwkStatus.
*
* @param os The output stream
* @param state The text value of the NWK state
* @return The output stream with text value of the NWK state
*/
std::ostream& operator<<(std::ostream& os, const NwkStatus& state);

/**
* @ingroup zigbee
*
Expand Down
3 changes: 1 addition & 2 deletions src/zigbee/test/zigbee-rreq-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ ZigbeeRreqRetryTestCase::NwkNetworkDiscoveryConfirm(ZigbeeRreqRetryTestCase* tes
}
else
{
NS_ABORT_MSG(
"Unable to discover networks | status: " << static_cast<uint32_t>(params.m_status));
NS_ABORT_MSG("Unable to discover networks | status: " << params.m_status);
}
}

Expand Down

0 comments on commit 6506f44

Please sign in to comment.