bgp: bug fix of handling nexthop for eBGP peering

RyuBGP doesn't work properly becase of handling wrong nexthop address.
Therefore, in spite of receiving BGP UPDATE Message in the peering router,
the router fails to learn a new route entry from RyuBGP in BGP table.
(Memo: this issue has not occurred in Vpnv4/mpBGP environment.)

(1) register route entry as prefix_add(prefix='x,x,x,x', next_hop='y.y.y.y')

                 static               eBGP
    ------- R1 ------------ RyuBGP ---------> Router
    x.x.x.x   y.y.y.y            z.z.z.z       => Drop UPDATE(Nexthop: y.y.y.y)

(2) receiving BGP UPDATE Message from iBGP session

                 iBGP                 eBGP
    ------- R1 -----------> RyuBGP ---------> Router
    x.x.x.x   y.y.y.y            z.z.z.z       => Drop UPDATE(Nexthop: y.y.y.y)

Signed-off-by: Toshiki Tsuboi <t.tsubo2000@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
ofctl_v1_/2/3: Modify match_to_str() to use new match field parser

Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
ofctl_v1_/2/3: Modify to_match() to use new match api

Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
test_ofctl: Modify to use new match api and field parser

Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Workaround of os.path.samefile

os.path.samrfile not implemented on Windows. Adding alternative using
os.stat

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
fix security problem of some RESTful apps

I'm very sorry I didn't include rest_firewall.py and rest_qos.py in my patch.
I suggested for ofctl_rest.py only...

Here is the patch for rest_firewall.py and rest_qos.py.

---------------------------------------------------------------
Subject: [PATCH] fix security problem of some RESTful apps

It is not safe to use eval function because input data(request body) is not checked
For example, someone can send this data to remove all files in the directory
"import('os').system('rm -rf .')"

I suggest to use json.loads to parse the request body if the data is json format
or disable builtin functions like:
eval(req.body, {"__builtins__":None})

Signed-off-by: Takeshi <a86487817@gmail.com>
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
ofctl_v1_2/3: Fully support the match combinations for VLAN ID

Currently, when VLAN ID match field is specified,
ofctl_v1_[23] is compatible with only match combination 1) of
the following three match combinations.
This patch makes it possible to set the all three combinations.

  Match combinations for VLAN ID :
    1) To match only packets with VLAN tag and VID equal value
    2) To match only packets without a VLAN tag
    3) To match only packets with a VLAN tag regardless of its value

In order to set the match combinations 2) or 3), please describe
"dl_vlan" field as hexadecimal string value like as follows.

  Before applying this patch:
    {"dl_vlan": 3 }              # int

  After applying this patch:
    {"dl_vlan": 3 }              # int (same as before applying)
    {"dl_vlan": "0x0000"}        # hexadecimal string without mask
    {"dl_vlan": "0x1000/0x1000"} # hexadecimal string with mask

NOTE: When "dl_vlan" field is described as decimal int value,
      OFPVID_PRESENT(0x1000) bit is automatically applied.
      OTOH, OFPVID_PRESENT(0x1000) bit is NOT automatically applied
      to hexadecimal string value.

For curl command examples, please refer to the following page in Ryu-documentation.
http://ryu.readthedocs.org/en/latest/app/ofctl_rest.html#example-of-vlan-id-match-field

Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
doc/app/ofctl_rest: Add command examples for OFPVID_NONE/PRESENT

Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
bmp: bug fix of peer bgp ID in BMP Message

Ryu BGP sets self-BGP ID as Peer BGP ID in BMP Message.

Signed-off-by: Yuji Oshima <yuji.oshima0x3fd@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
packet lib: don't crash with bogus ospf packet

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Ryu 3.16

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
ofproto_v1_[234]_parser: Add notes for vlan_vid match field

To make it possible to refer the usage of vlan_vid match field
at Ryu-documentation, This patch adds notes into ofproto_v1_[234]_parser.

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
ofctl_v1_3: Fix to parse capabilities field in OPFMeterFeatures

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
doc/app/ofctl_rest: Add description for capabilities field in OPFMeterFeatures

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
bgp: support new handler in case of changing BGP session

When BGP session goes up/down, BGPSpeaker can detect changing the session.

Signed-off-by: Toshiki Tsuboi <t.tsubo2000@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
rest_qos: fix a comment

Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
rest_qos: fix error of additional a qos rule with "priority"

Currently, rest_qos is impossible to set the "priority" of QoS rule on a switch.
Also, "priority" is should be described in the same depth as "match" and "actions".
This patch fixes these problems.

Now, rest_qos is possible to set the "priority" with the following curl command.

e.g.)
  $ curl -X POST -d '{"priority":"5",
                      "match": {"nw_dst": "10.0.0.1", "nw_proto": "UDP", "tp_dst": "5002"},
                      "actions":{"queue": "1"}}' http://localhost:8080/qos/rules/0000000000000001

Reported-by: Jace Liang <b436412@gmail.com>
Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
First commit of QoS:
* rate-limit works
* dscp works. Note that it works only with an integer value multiple of 4 and in the range 4:252
* TODO: remove some unnecessary code of QoSEvent and some debug print
Merge branch 'qos' of https://github.com/SmartInfrastructures/ryu into qos
add empty README.qos