bgp: fix _OptParamCapability parser

It could include multiple Capabilities.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
bgp: remove uncommon open msg check

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
doc: Add tables about match and actions structures

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
ofctl_v1_0: Add remaining actions

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
bgp/cli: show adjacency rib in/out by show neighbor commands

show neighbor sent-routes/received-routes commands used to show the
routes in local rib, but the right behavior is to show adjacency rib
in/out.

Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
bgp: fix lacking import

Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
bgp: enable to stop a chile thread by specifying its name

Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
bgp: support connect modes to choose how to connect to the neighbors

three connect modes are supported

    CONNECT_MODE_ACTIVE: try to connect from us. don't listen
    CONNECT_MODE_PASSIVE: just listen
    CONNECT_MODE_BOTH: try both methods

dynamic change of connect modes is also supported

Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
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})

In this patch, ast.literal_eval() is used to evaluate REST body,
because ofctl_rest needs to be compatible with hexadecimal value
or ascii byte array (e.g. "\x00\x00\x00\x01" in Experimenter)
in order to keep usability.

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>
doc/app/ofctl_rest: Correct command examples

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
ofctl_rest: fix some mistypes

In ryu/app/ofctl_rest.py found some mistypes. Error gets when using
stats/groupdesc/<dpid> and /stats/groupfeatures/<dpid>

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
bgp: bug fix of Multi Exit Discriminator (MED)

RyuBGP doesn't work well regarding the advertisement of BGP MED Attribute as follows.

(1) In spite of receiving BGP MED:"500" from iBGP(R2), RyuBGP can't advertise BGP MED:"100" to eBGP(R3).

    R1 -------------> R2 -------------> RyuBGP -------------> R3
       eBGP(MED:500)     iBGP(MED:500)    ^     eBGP(MED:500)
                                       (MED:100)

(2) When RyuBGP has received BGP MED:"200" from eBGP(R3), RyuBGP has sended BGP with missing-MED to iBGP(R2).
    As result, PolicyBaseRouting in R2(other RyuBGP) doesn't work properly becase of selecting wrong BestPath.

                   eBGP(MED:100)
    R1 ------------------------------------>+
                                            |
    R3 -------------> RyuBGP -------------> R2(RyuBGP) => Wrong result [BestPath is "R3-R2"]
       eBGP(MED:200)          iBGP(MED:N/A)

Signed-off-by: Toshiki Tsuboi <t.tsubo2000@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
test_ofctl_v1_2/3: Fix some test cases

UnitTest of the following cases had not been executed successfully.

{'dl_src/dst': "aa:bb:cc:11:22:33/*"}
{'eth_src/dst': "aa:bb:cc:11:22:33/*"}
{'nw_src/dst': "192.168.0.1/*", 'eth_type': 0x0800}
{'ipv4_src/dst': "192.168.0.1/*", 'eth_type': 0x0800}
{'arp_spa/tpa': "192.168.0.22/*", 'eth_type': 0x0806}
{'arp_sha/tha': "aa:bb:cc:11:22:33/*", 'eth_type': 0x0806}
{'ipv6_src/dst': '2001::aaaa:bbbb:cccc:1111/*', 'eth_type': 0x86dd}

This patch fixes this problem.

Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
test_ofctl_v1_2/3: Add a test case of masked metadata

Signed-off-by: Minoru TAKAHASHI <takahashi.minoru7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
utils: Fix bytearray conversion

The parameter buf is an instance of bytearray, but Ryu tries to convert it as string,
and outputs the error messages as a result.
This patch fixes this problem.

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
test_utils: Add unit test for ryu.utils

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
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>