of12: fix OFPExperimenter parser

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of12 OFPGroupFeaturesStats: add missing self.length

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of13: add missing itertools import

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of13 fix OFPGroupFeaturesStats parser

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of13 fix multipart reply parsing

make the parser return specific classes like OFPGroupFeaturesStatsReply
instead of always returning OFPMultipartReply.

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of13 fix OFPQueueProp parsing

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of13 OFPExperimenter: fix parser and remove completely broken serializer

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of13 OFPGroupDescStats: fix super call

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of13 OFPBucket: fix a fatal typo

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
quantum_adapter: check if quantum_controller_addr is valid

With this, more understandable error will be produced.
Otherwise it results in mysterious error like

transaction error: {"details":"Table Bridge column controller row 69da7121-51fa-4d6e-ad24-18ff9c857b87 references nonexistent row 17c4aa64-ed91-4d8a-a905-a137e6969ad9 in table Controller.","error":"referential integrity violation"}
hub: uncaught exception: Traceback (most recent call last):
  File "/ryu/ryu/lib/hub.py", line 50, in _launch
    func(*args, **kwargs)
  File "/ryu/ryu/base/app_manager.py", line 104, in _event_loop
    handler(ev)
  File "/ryu/ryu/app/quantum_adapter.py", line 383, in conf_switch_set_handler
    self._conf_switch_set_ovsdb_addr(ev.dpid, ev.value)
  File "/ryu/ryu/app/quantum_adapter.py", line 372, in _conf_switch_set_ovsdb_addr
    ovs_switch.set_ovsdb_addr(dpid, value)
  File "/ryu/ryu/app/quantum_adapter.py", line 169, in set_ovsdb_addr
    ovs_bridge.set_controller([self.ctrl_addr])
  File "/ryu/ryu/lib/ovs/bridge.py", line 128, in set_controller
    self.run_command([command])
  File "/ryu/ryu/lib/ovs/bridge.py", line 101, in run_command
    self.vsctl.run_command(commands, self.timeout, self.exception)
  File "/ryu/ryu/lib/ovs/vsctl.py", line 1006, in run_command
    self._run_command(commands)
  File "/ryu/ryu/lib/ovs/vsctl.py", line 999, in _run_command
    self._do_main(commands)
  File "/ryu/ryu/lib/ovs/vsctl.py", line 927, in _do_main
    if self._do_vsctl(idl_, commands):
  File "/ryu/ryu/lib/ovs/vsctl.py", line 898, in _do_vsctl
    vsctl_fatal('transaction error: %s' % txn_.get_error())
  File "/ryu/ryu/lib/ovs/vsctl.py", line 132, in vsctl_fatal
    raise Exception(msg)        # not call ovs.utils.ovs_fatal for reusability
Exception: transaction error: {"details":"Table Bridge column controller row 69da7121-51fa-4d6e-ad24-18ff9c857b87 references nonexistent row 17c4aa64-ed91-4d8a-a905-a137e6969ad9 in table Controller.","error":"referential integrity violation"}

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
packet lib: avoid exception for bogus protocol header parsing

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of13: Added InstructionMeter

Signed-off-by: Philipp Aeschlimann <aepp@zhaw.ch>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
datapath_connection_factory deal with None datapath.id

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
nx_match: some comments

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of12: prefix private attributes of OFPMatch with _

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
of13: prefix private attributes of OFPMatch with _

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
ofctl_v1_2.actions_to_str: ignore unknown instructions

avoid crashing when the switch happens to have flows with
non OFPInstructionActions instructions.

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
gre_tunnel: exception due to race condition

This depends on thread scheduling.
When event handler is invoked, there may not corresponding network_id in
network module.
So add ports attribute to EventNetworkDelete event so that the event
handler can know the necessary information without listing ports of the
given network id.

> 127.0.0.1 - - [19/Jun/2013 11:24:25] "DELETE
> /v1.0/networks/8179bb70-a63f-4c74-a82e-a21f3c275c9a HTTP/1.1" 200 115 0.000488
> hub: uncaught exception: Traceback (most recent call last):
>   File "/opt/stack/ryu/ryu/lib/hub.py", line 50, in _launch
>     func(*args, **kwargs)
>   File "/opt/stack/ryu/ryu/base/app_manager.py", line 104, in _event_loop
>     handler(ev)
>   File "/opt/stack/ryu/ryu/app/gre_tunnel.py", line 210, in network_del_handler
>     for (dpid, port_no) in self.nw.list_ports(network_id):
>   File "/opt/stack/ryu/ryu/controller/network.py", line 319, in list_ports
>     return self.networks.list_ports(network_id)
>   File "/opt/stack/ryu/ryu/controller/network.py", line 97, in list_ports
>     raise NetworkNotFound(network_id=network_id)
> NetworkNotFound: no such network id 8179bb70-a63f-4c74-a82e-a21f3c275c9a

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
gre_tunnel.py: race condition

When tunnel key add/del event fires, the corresponding network_id
does not necessarily exists due to race condition.
So mask it.

(15612) accepted ('127.0.0.1', 45714)
127.0.0.1 - - [25/Jun/2013 12:18:18] "DELETE
/v1.0/networks/462be334-3160-48ae-9ef8-a456dc866f8f HTTP/1.1" 200 115
0.000393
(15612) accepted ('127.0.0.1', 45715)
127.0.0.1 - - [25/Jun/2013 12:18:18] "DELETE
/v1.0/tunnels/networks/462be334-3160-48ae-9ef8-a456dc866f8f/key
HTTP/1.1" 200 115 0.000260
hub: uncaught exception: Traceback (most recent call last):
  File "/opt/stack/ryu/ryu/lib/hub.py", line 50, in _launch
    func(*args, **kwargs)
  File "/opt/stack/ryu/ryu/base/app_manager.py", line 104, in _event_loop
    handler(ev)
  File "/opt/stack/ryu/ryu/app/gre_tunnel.py", line 233, in
tunnel_key_del_handler
    for (dpid, port_no) in self.nw.list_ports(network_id):
  File "/opt/stack/ryu/ryu/controller/network.py", line 325, in list_ports
    return self.networks.list_ports(network_id)
  File "/opt/stack/ryu/ryu/controller/network.py", line 103, in list_ports
    raise NetworkNotFound(network_id=network_id)
NetworkNotFound: no such network id 462be334-3160-48ae-9ef8-a456dc866f8f

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
simple_vlan.py: race condition

When tunnel key is registers, network is is not always
registered.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>