of13: add missing UINTxx_MAX

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
ofproto: exception during startup related ofp module detaction

This patch fixes the following exception.

ryu/controller/ofp_event.py: update
cd /opt/stack/ryu && /opt/stack/ryu/bin/ryu-mana ^Mger --config-file /etc/ryu/ryu.conf || touch "/opt/stack/status/stack/ryu.failur ^Me"
> Traceback (most recent call last):
>   File "/opt/stack/ryu/bin/ryu-manager", line 41, in <module>
>     from ryu.base.app_manager import AppManager
>   File "/opt/stack/ryu/ryu/base/app_manager.py", line 22, in <module>
>     from ryu.controller.handler import register_instance
>   File "/opt/stack/ryu/ryu/controller/handler.py", line 20, in <module>
>     from ryu.controller import ofp_event
>   File "/opt/stack/ryu/ryu/controller/ofp_event.py", line 69, in <module>
>     for ofp_mods in ofproto.get_ofp_module():
> TypeError: get_ofp_module() takes exactly 1 argument (0 given)

Reported-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
tests/ofproto: add unit test for ofproto automatic detection

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.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>
debug_console: monkey patch code.InterractiveConsole.raw_input

By default code.InteractiveConsole.raw_input uses builtin raw_input
which is written in C. So it may not yeild thread execution, and other
threads aren't scheduled.
replace code.InteractiveConsole.raw_input with thread friendly one.
Thus Ryu works as expected with debug_console app.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
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/switches: exception during serialization

Datapath.send_packet_out() requires buffer_id, not dpid.

> Traceback (most recent call last):
>   File "/usr/lib/pymodules/python2.7/gevent/greenlet.py", line 390, in run
>     result = self._run(*self.args, **self.kwargs)
>   File "ryu/base/app_manager.py", line 126, in _event_loop
>     handler(ev)
>   File "/ryu/topology/switches.py", line 697, in packet_in_handler
>     self._drop_packet(msg)
>   File "/ryu/topology/switches.py", line 640, in _drop_packet
>     dp.send_packet_out(dp.id, msg.in_port, [])
>   File "/ryu/controller/controller.py", line 242, in send_packet_out
>     self.send_msg(packet_out)
>   File "/ryu/controller/controller.py", line 216, in send_msg
>     msg.serialize()
>   File "/ryu/ofproto/ofproto_parser.py", line 119, in serialize
>     self._serialize_body()
>   File "/ryu/ofproto/ofproto_v1_0_parser.py", line 1987, in _serialize_body
>     self.buffer_id, self.in_port, self.actions_len)
>   File "/ryu/ofproto/ofproto_parser.py", line 128, in msg_pack_into
>     buf += struct.pack(fmt, *args)
> error: 'I' format requires 0 <= number <= 4294967295
> <Greenlet at 0x229bd98: <bound method Switches._event_loop of <switches.Switches object at 0x1c8e690>>> failed with error

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: 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 v1 -> v2:
- improve commit message
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.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
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.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
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
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.

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

Changes v2 -> v3:
- comment

Changes v1 -> v2:
- dynamic configuration change
- wrong priority comparison
services/vrrp/manager: introduce a class that manages VRRP routers

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
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.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v2 -> v3:
- drop register request api

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

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

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
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