RFMonitor init

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Message to register Controller with RFMonitor

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Conform to PEP8

Added 2 newlines between classes. Removed an unused import pymongo.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Register controller with RFMonitor

For communication between controller instance and RFMontor defined a new
channel id and RFMonitor instance id. Added message processor in
RFMonitor that stores the details of controller instances with RFMonitor instance

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Automated ControllerRegister message generation.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Acked-by: Joe Stringer <joestringernz@gmail.com>
PEP8 conformed code generation by mesgen.py

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Test to check if a controller is alive.

To check if controller is up and running, create a socket and try to
connect it to the listening host and port of the controller. If the
controller is dead, then delete the corresponding entry from RFMonitor
instance.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Handle controller spawn and death

When a controller is spawned its details are registered with RFMonitor
and a `Monitor` is initialized for the controller that is responsible
for testing periodically if controller is alive. When a controller dies,
entries corresponding to the controller are removed from RFMonitor and
periodic test going on the controller is stopped.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Monitor class for scheduling tests on controller.

When the test starts, the monitor continuously tests for controller
failure at time intervals equal to `callback_time` which is currently
equal to 1 second. The class exposes an API to RFMonitor for starting
and stoping tests.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Modified rftest1 for HA

Starts RFMonitor to monitor controller failure and two controller
instances with one as master and other as slave.
Openvswitch connects to both the controllers and sends info only to
master connection.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Docstring for functions.

Docstring for various functions describing the purpose and keyword
arguments passed to the functions.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Set socket used for test to non-blocking.

The socket being used to check if a controller is alive was blocking. It
blocked until it was able to connect to the given host and port.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Code refactor to handle controller failure.

The test function that was responsible for checking if a controller is
alive had the code to amend RFMonitor instance and stop test. Now it has
been refactored to a new function that is invoked by the test function.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Lock for controllers dict.

There are two threads running in RFMonitor, one for testing and other
for scheduling. Both the threads use controllers dictionary. So to
prevent the condition of simultaneous usage of the data structure by the
two threads, the data structure is locked when it is being used by one
of the threads and released as soon as changes are done.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Acked-by: Joe Stringer <joestringernz@gmail.com>
Handle testing and IPC on separate threads.

RFMonitor has two threads, on for IPC and other for testing. The earlier
architecture made IPC thread invoke testing functions. So this patch
segregates the two threads, with the main thread handling testing on the
given dictionary of controllers and IPC thread adding new entries to
dictionary when new controller spawns.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Acked-by: Joe Stringer <joestringernz@gmail.com>
Merge pull request #1 from routeflow/vandervecken

Minor Vandervecken fixups

* Generally tidy up the codebase
* Update git URLs, fix dependency issues
* New commandline arguments for rftest to run via different controllers
* Use RFC1918 addressing for the virtual router

https://github.com/routeflow/RouteFlow/pull/1
Dict Lock, default timeout and schedule test check.

The data structure controller dictionary is being shared between IPC and
main thread, so put a lock on it when it is being used by one of them.

The timeout initial value for a test was set to 0.0 which is changed to
current time.

A flag was checked before a test was scheduled on a controller. Due to
modified control flow this condition will not arise so removed the flag
check from the schedule_test function.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Acked-by: Joe Stringer <joestringernz@gmail.com>
Keep count of devices connected to controllers.

To elect new master controller in case the master controller goes down,
the controller with maximum devices associated with it will be promoted.
To facilitate this, RFMonitor will maintain the count of the number of
devices associated with it.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Master election by RFMonitor.

When a master controller dies a new master is to be elected among the
remaining controllers. A dictionary of eligible masters is maintained by
the RFMonitor which is updated periodically as a new controller comes or
the load on existing controllers increase. When a master dies a master
is selected from these eligible controllers. This patch implements the
required changes at RFMonitor level to elect a new master.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
New message to elect a new master.

When a master controller dies, a new master is elected at RFMonitor and
it is to be informed to the rfproxy and inturn all the devices. So a new
message type ELECT_MASTER is created that will be used by RFMonitor to
inform the rfproxy.

Signed-off-by: Srijan Mishra <srijan23mishra@gmail.com>
Acked-by: Joe Stringer joestringernz@gmail.com