rftest2: Consolidate VM creation and setup logic

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rftable: Fix pep8 style issues

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfserver: Fix pep8 style issues

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfserver: Add default config paths

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfserver: Don't catch exceptions in main()

We have previously been catching exceptions in the main() function of
RFServer, and describing all failures as a failure to open the config
file. In the best case, this behaviour simply hides information that may
be useful for debugging. In the worst case, it misleads the user as to
where the problem is. This patch removes the code to catch these
exceptions, allowing the default handler to print the correct message.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfclient: Don't keep track of down_ports

The list of 'down_ports' is unused, inefficient, and it's not
thread-safe. Remove it in favour of checking Interface.active.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfclient: Remove unused member init_ports

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfclient: Rework load_interfaces()

load_interfaces() used to do a combination of loading and also changing
the state of RFClient. Now it's just a function that fetches all of the
system interfaces, and returns a vector containing them.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rflib: Fix clang build warnings

Signed-off-by: Joe Stringer <joe@wand.net.nz>
Refactor port mapping to separate class/thread

This patch refactors the logic for mapping RFVS-VM ports into a separate
class, run in a separate thread. Rather than sending the packet once at
startup and never trying again, we now periodically send the packet out
each port. Currently this is every 10 seconds.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfclient: Refactor storage of Interface objects

This patch introduces a new abstract class, InterfaceMap and makes
RFClient subclass this. This allows the main thread to maintain the
collection of Interfaces and provide access to them in a thread-safe
manner. In future, this will assist with handling changes in Interface
status, and the ability to set ports administratively up/down.

FlowTable now makes use of this abstract class to get up-to-date
Interface information on-demand.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfclient: Rework port configuration messaging

Previously, when a virtual switch joined, the following occurred:-
1) VS notifies RFProxy
2) RFProxy notifies RFServer
3) RFServer notifies RFClient
4) RFClient sends a single ethernet packet out a port to determine VS
   port mapping
5) VS forwards to RFProxy with port information
6) RFProxy notifies RFServer
7) RFServer maps ports, tells RFProxy about VM-DP mapping
8) RFProxy stores VM-DP Mapping

This patch removes step 3, and makes step 7 also notify RFClient. When
RFClient is notified that the mapping has been successfully established,
it sets the interface state to "active". This allows cached routes with
egress via this interface to be pushed to the associated datapath.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfclient: Style tidyups

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfclient: Don't drop routes for inactive interfaces

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfclient: Consolidate logging output to syslog

We've previously been using a gajillion different methods to output
logging information---fprintf, streams, syslog, perror, custom logging
macros. This patch consolidates all of these and makes them output to
syslog in a thread-safe manner instead.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
FlowTable: Keep track of deleted routes

If a route "add" occurs, and the route cannot be resolved, then
GWResolver will cache the route and continue attempting to insert it. If
the kernel attempts to delete this route while it is cached, then the
removal will be discarded, as the route does not exist in the routeTable.
However, the original "add" will remain cached, which causes a mismatch
between the kernel state and our final datapath state.

This patch adds a "deletedRoutes" map to keep track of these, and makes
GWResolver check this map for a given route before attempting to add it.
For route adds, this will remove the route from the deletedRoutes map
and discard the route. For route deletes, this will also remove the
route from the deletedRoutes map and attempt to remove the route from
the routeTable.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
GWResolver: Sleep when things are quiet

GWResolver seems to have come down with a bad case of narcolepsy. If
there are cached routes that cannot be instantly resolved, they'll go to
the back of the list. If we see the same route again really soon, we get
bored and go back to sleep for a while.

New routes coming in will not be processed until GWResolver wakes up,
but that should be O.K. as the timeouts run in parallel; In the worst
case, there are a large number of pending routes, then there is a flood
of new routes come in. The new routes are queued at the end of the list,
and we sleep until the first route's timeout. All of the original
pending routes should have quite close timeout values, so we should be
able to process through the entire list fairly quickly.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
PortMapper: Don't exit on error

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfclient: Rework commandline argument parsing

This enables the previously-commented argument "-n" to specify an ID for
the client, and adds a usage message when specifying invalid arguments.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
rfclient: Don't exit if no interfaces were found

Signed-off-by: Joe Stringer <joe@wand.net.nz>