helium / helium-packet-router

Apache License 2.0
8 stars 5 forks source link

SKFs sync issue #293

Closed macpie closed 4 months ago

macpie commented 4 months ago

It seems like refresh a route does not work.

Running this: hpr config route refresh

and then this in a shell:

f(),
F = fun() ->
    Map = lists:foldl(
        fun(RouteETS, Acc) ->
            Route = hpr_route_ets:route(RouteETS),
            ID =  hpr_route:id(Route),
            Size = ets:info(hpr_route_ets:skf_ets(RouteETS), size),
            case Size > 1000 of
                true -> maps:put(ID, Size, Acc);
                false -> Acc
            end
        end,
        #{},
        ets:tab2list(hpr_routes_ets)
    ),
    io:format("~p~n", [Map])
end,
F().

show that nothing really changed

macpie commented 4 months ago

Full refresh

f(),
F = fun() ->
    RouteIDs = [hpr_route:id(R) || R <- hpr_route_storage:all_routes()],
    Total = length(RouteIDs),

    TimeIt = fun(Func) ->
        {Time0, Val} = timer:tc(Func),
        Time = erlang:convert_time_unit(Time0, microsecond, millisecond),
        io:format("took ~pms~n", [Time]),
        Val
    end,

    Refresh = fun({Idx, ID}) ->
        io:format("~n~p/~p===========================================================~n", [Idx, Total]),
        TimeIt(fun() -> 
            try hpr_route_stream_worker:refresh_route(ID) of
                {ok, Map} -> 
                    io:format("| Type | Before | After | Removed | Added |~n"),
                    io:format("|------|--------|-------|---------|-------|~n"),
                    io:format("| ~4w | ~6w | ~5w | ~7w | ~5w |~n", [eui, maps:get(eui_before, Map), maps:get(eui_after, Map), maps:get(eui_removed, Map), maps:get(eui_added, Map)]),
                    io:format("| ~4w | ~6w | ~5w | ~7w | ~5w |~n", [skf, maps:get(skf_before, Map), maps:get(skf_after, Map), maps:get(skf_removed, Map), maps:get(skf_added, Map)]),
                    io:format("| ~4w | ~6w | ~5w | ~7w | ~5w |~n", [addr, maps:get(devaddr_before, Map), maps:get(devaddr_after, Map), maps:get(devaddr_removed, Map), maps:get(devaddr_added, Map)]);
                {error, _R} ->
                    io:format("ERROR ~p~n", [_R])
            catch
                _E:_R ->
                    io:format("CRASHED ~p~n", [_R])
            end
        end)
    end,
    [Refresh(ID) || ID <- lists:zip(lists:seq(1, Total), RouteIDs)]
end,
F().