Skip to content

Commit

Permalink
Small changes to alias allocator:
Browse files Browse the repository at this point in the history
- adds accessor to get the node id used for allocation.
- fixes todo to check whether newly generated aliases are in the existing caches.
- adds ability to get the next proposed alias from the sequence.
  • Loading branch information
balazsracz committed Nov 14, 2020
1 parent 983502f commit 2ada534
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/openlcb/AliasAllocator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ StateFlowBase::Action AliasAllocator::entry()
HASSERT(pending_alias()->state == AliasInfo::STATE_EMPTY);
while (!pending_alias()->alias)
{
pending_alias()->alias = seed_;
next_seed();
// TODO(balazs.racz): check if the alias is already known about.
pending_alias()->alias = get_new_seed();
}
// Registers ourselves as a handler for incoming CAN frames to detect
// conflicts.
Expand All @@ -124,6 +122,24 @@ StateFlowBase::Action AliasAllocator::entry()
return call_immediately(STATE(handle_allocate_for_cid_frame));
}

NodeAlias AliasAllocator::get_new_seed()
{
while (true)
{
NodeAlias ret = seed_;
next_seed();
if (if_can()->local_aliases()->lookup(ret))
{
continue;
}
if (if_can()->remote_aliases()->lookup(ret))
{
continue;
}
return ret;
}
}

void AliasAllocator::next_seed()
{
uint16_t offset;
Expand Down
11 changes: 11 additions & 0 deletions src/openlcb/AliasAllocator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,24 @@ public:
*/
AliasAllocator(NodeID if_id, IfCan *if_can);

/** Destructor */
virtual ~AliasAllocator();

/** @return the Node ID for the interface. */
NodeID if_id()
{
return if_id_;
}

/** Resets the alias allocator to the state it was at construction. useful
* after connection restart in order to ensure it will try to allocate the
* same alias. */
void reinit_seed();

/** Returns a new alias to check from the random sequence. Checks that it
* is not in the alias cache yet.*/
NodeAlias get_new_seed();

/** "Allocate" a buffer from this pool (but without initialization) in
* order to get a reserved alias. */
QAsync *reserved_aliases()
Expand Down

0 comments on commit 2ada534

Please sign in to comment.