xorp: rib: Make RouteEntry more generic

Make RouteEntry more generic, by making it templetized.
Move _net and _policitags to this class, because all classes that inherit it are using those fields.

IPRouteEntry overides the nexthop function of RouteEntry with different NextHop type.
To be more specific it overides it with IPNextHop type.

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Use operator* instead of payload() method for Trie class

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: templatize RibVif class

Make RibVif's class interface cleaner and easier to understand.

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: IPRouteEntry directly return NextHop of appropriate type

IPRouteEntry has member of IPNextHop type. It now returns nexthop of
IPNextHop type, without dynamic_casting.
This alows us to avoid unecesary casting!

DiscardNextHop and UnreachableNextHop directly inherit from
IPNextHop.

Passed all rib tests.

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Make helper functions be static RibManager members

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Templatize PolicyRedistTable by introducing PolicyRedistClient

PolicyRedistClient is template class. It is used as wrapper for XrlPolicyRedist4V0p1Client
and XrlPolicyRedist6V0p1Client, for now, to call send_delete_route{4, 6} and send_add_route{4, 6}
uniformerly by calling functions send_delete_route and send_add_route.

By doing that we don't need to specialize add_redist and delete_redist functions.

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Fix memory leak in ExtIntTable

Add destructor that frees all entries from _ip_unresolved_table
and _ip_route_table.

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Fix memory leak in RegisterTable

Added destructor that frees all entries from _ipregistry.
Also in function register_route_range, route range obtained with
lookup_route_range is freed.

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Implemented PolicyRedistTable<A>::str()

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Implemented PolicyConnectedTable<A>::str()

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Efficient handling of route tables

All route tables aren't stored any more in one large list. Instead,
each route table, that can have multiple instances in RIB,
has it's own map.
That's why we have MergedTable map, RedistTable map and
OriginTable map.
To provide faster lookup of OriginTables OriginTable map is
splited in two maps - IGP OriginTable map and EGP OriginTable map.

Each route table map has it's own apropriate function for
searching RoutTable entry. OriginTable map has three lookup
functions. One global search function, and one for IGP and EGP maps.
Tables are added in appropriate via overloaded add_route function.

Because we can have only one instance of RegisterTable,
PolicyRedistTable, PolicyConnectedTable and ExtIntTable, they
aren't stored in maps. They are saved as class members.

In code, find_table is replaced with apropriate
find_{origin, igp_origin, egp_origin, merged, redist} calls.
That way a lot of dynamic_cast is avoided!

print_rib() method is pretified, so it would print RoutTables
as they are stored now.

All rib tests passed.

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Split add_origin_table into smaller units

Added four new functions:
plumb_origin_table - checks existing tables and plumbs origin
table appropriately
plumb_ahead_of_first - plumbs origin table ahead of first
existing table in tree
plumb_ahead_of_merged - creates Merged table and plumbs origin
table ahead of merged table.
plumb_ahead_of_ext_int - creates ExtInt table and plumbs origin
table ahead of ExtInt table

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Make add_route more efficient

When looking if the route is directly connected or not, we only need
to look in connected OriginTable. For that reason, save that table
in a pointer and perform lookup directly in that table.
If the route is not found in connected origin table, we don't need
to loop through all vifs, because vif addresses are dinamically
added/removed from the connected table. Also removed
find_vif(const A& addr) because it isn't used any more.
Connected routes are added directly to vif - no need to loop
through existing vifs!
Passed all tests.

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Make OriginTable::add_route() more efficient

Instead of passing the reference to route, we pass
route pointer
This way of passing is more efficient because we only have to call
one IPRouteEntryConstructor instead of two.
Pointer shouldn't be changed after it was passed to this function.

Passed all rib tests.

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: rib: Fixed register test

Checking of verifytype in test_route_range was wrong.
If we got route check if we expected it.
If we got the Discard, or Unreachable, route, don't need to
check any more.
If we didn't go the route check if we expected the miss.

Signed-off-by: Igor Maravic <igorm@etf.rs>
xorp: policy: Fix usage of network{4,6}-lists

Add '~' as string distguisher, instead of ' '.
Also add posible completions to policy template.

Reported-by: Jens Dackenberg <jens.devel@gmail.com>
Signed-off-by: Igor Maravic <igorm@etf.rs>
trivial: ws fixes
xorp: rib: Add commands for testing adding and deleting of interface routes
xorp: fea: data_plane: fibconfig: Fix using of rtmsg scope parameter

When the route doesn't have the specified gateway or nexthop it's scope should be link(RT_SCOPE_LINK).
Otherwise it should be global(RT_SCOPE_UNIVERSE).

Referenced from iproute2.
xorp: fea: data_plane: fibconfig: Fix using of rtmsg scope parameter in delete_entry

When deleting route we should use RT_SCOPE_NOWHERE instead of RT_SCOPE_UNIVERSE.

Reported-by: Jiangxin Hu <jiangxin.hu@crc.gc.ca>