ryu/base/app_manager.py: debug log state

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
pep8: ryu/app/gre_tunnel.py

ryu/app/gre_tunnel.py:398:13: E128 continuation line under-indented for visual indent
            PortSet.EventTunnelPort, ofp_event.EventOFPPacketIn])
            ^

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
pep8: ryu/lib/xflow/netflow.py

ryu/lib/xflow/netflow.py:120:14: E121 continuation line indentation is not a multiple of four
             cls._PACK_STR, buf, offset)
             ^

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
ofproto: _baseattribute can be class attribute

So that it can save memory a bit.

Cc: yamamoto@valinux.co.jp
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
ryu-manager: introduce option to enable cgitb

More comprehensive traceback with cgitb is useful for debugging.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
add a ryuapp to provide python interactive console for debugging

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
---
Changes v1 -> v2:
- use native threading
ryu/utils: import_module() can load wrong module

ryu-manager ryu/topology/dumper.py ryu/services/vrrp/dumper.py
results in loading ryu.topology.dumper twice.
ryu/services/vrrp/dumper.py is not loaded.
And also don't populate sys.path multiple times with same path.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
topology: split out exported API from the implementation

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
base/app_manager: context might be RyuApp

The class used for context might be RyuApp. So methods of RyuApp needs
to be called.

Reported-by: YAMADA Hideki <yamada.hideki@po.ntts.co.jp>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
base/app_manager: RyuApp initialization race at startup

There is a race between RyuApp instantiation and starting its thread.
Each RyuApp spawns an event-loop thread which handles events and may
generate events when a RyuApp instance is created.
Currently on startup, necessary RyuApps are created, and event-loop
thread is created at the same time. Then event-piping (which events are
delivered to which RyuApp) is done. This causes missing events if
RyuApp which was create early generates events before finishing event-piping.

To address it, split RyuApp startup into three phases from two phase.
- create RyuApp instances
- event piping
- then, start event-loop threads.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- fix GRE tunnel app
  It directly uses RyuApp so that it needs modification.

Changes v1 -> v2:
- improve commit message

app/gre_tunnel: teach RyuApp start/stop

Since GRETunnel directly creates RyuApp, PortSet. So it needs to be updated.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
base/app_manager: introduce singleton pattern to AppManager

Later VRRP service creates/deletes RyuApp dynamically as VRRP router
is enabled/disabled.
When creating/deleting RyuApp, unique RyuManager should be used.
There needs a way to get a unique RyuApp. So introduce singleton pattern

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v1 -> v2:
- improve commit message
base/app_manager: create/destroy RyuApp instances dynamically

allow RyuManager to create/destroy RyuApp instances dynamically
and register/unregister event observer dynamically.

Cc: yuta-hamada <yuta.hamada.z02@gimal.com>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- use app name for uninstantiate method instead of app instance

Changes v3 -> v4:
- eventlet
services/vrrp: introduce vrrp module

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
services/vrrp/utils: util functions for vrrp service

It will be used later by VRRP service.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
services/vrrp/event: introduce VRRP related events and classes

They are exported events and classes.

Cc: Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>
Cc: yuta-hamada <yuta.hamada.z02@gimal.com>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- add state attribute to VRRPInstance
-  ryu/services/vrrp/event.py", in __init__
   super(EventVRRPListReply, self).__init__() TypeError:
   __init__() takes exactly 2 arguments (1 given)

Changes v2 -> v3:
- make StateChanged event include related all configs
  this is useful for sample_manager/router
- drop register request

Changes v1 -> v2:
- Linux network device support
- dynamic configuration change

fixed argument for event.EventReplyBase constructor.
ryu/services/vrrp/event.py", in __init__
    super(EventVRRPListReply, self).__init__()
TypeError: __init__() takes exactly 2 arguments (1 given)
services/vrrp/monitor: introduce interface monitor

Introduce class that manages switch interface on which
VRRP works.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v3 -> v4:
- eventlet

Changes v2 -> v3:
- use MCAST_JOIN/LEAVE_GROUP which is more protocol independent
- introduce if_nametoindex which follows standard
- more comments

Changes v1 -> v2:
- Linux network device support
services/vrrp/router: VRRP router

Introduce VRRP router class which handles VRRP.

Cc: Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>
Cc: yuta-hamada <yuta.hamada.z02@gimal.com>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- router.py: vrrp_config_change_request AttributeError
  AttributeError: 'VRRPRouterV3' object has no attribute 'address_owner'
- self.state_impl.vrrp_config_chnage_request(ev)
  AttributeError: 'VRRPV3StateMaster' object has no
  attribute 'vrrp_config_chnage_request'

Changes v3 -> v4:
- eventlet

Changes v2 -> v3:
- comment

Changes v1 -> v2:
- dynamic configuration change
- wrong priority comparison

fixed method name.
ryu/services/vrrp/router.py",  in vrrp_config_change_request_handler
    self.state_impl.vrrp_config_chnage_request(ev)
AttributeError: 'VRRPV3StateMaster' object has no attribute 'vrrp_config_chnage_request'

fixed attribute name.
ev.Advertisement_inerval to ev.advertisement_interval
services/vrrp/manager: introduce a class that manages VRRP routers

Cc: yuta-hamada <yuta.hamada.z02@gimal.com>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- manager.py: list_request_handler TypeError
  TypeError: __init__() takes exactly 5 arguments (4 given)
- appmanager.uninstantiate argument change
- add state to VRRPInstance

Changes v3 -> v4:
- eventlet

Changes v2 -> v3:
- comment
- typo
- drop register request handler

Changes v1 -> v2:
- dynamic configuration change
- trivial update for depending patch change
services/vrrp/api: API for VRRP service

API for VRRP service exported to other RyuApp.

Cc: Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- corrected arguments for send_request at vrrp_list method.
  modified to use send_event at vrrp_config_change method.
- pep8

Changes v2 -> v3:
- drop register request api

Changes v1 -> v2:
- dynamic configuration change
services/vrrp/sample: sample manager/router code

Sample manager/router code.
Real router app can use this code as template in order to support VRRP.

Cc: yuta-hamada <yuta.hamada.z02@gimal.com>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- uninstantiate argument change

Changes v3 -> v4:
- eventlet

Changes v2 -> v3:
- introduce sample manager which dynamically creates/deletes router
- typo, comment
- fix garp packet
- arp processing
- simplify sample router code by transmit request

Changes v1 -> v2:
- sample for Linux network device
- trivial update
  arp_ether_ip -> arp_ip
- don't rely on packet-in match field for packet parsing