AT_BANNER([ovs-router])

AT_SETUP([appctl - route/add with gateway and pkt_mark])
AT_KEYWORDS([ovs_router])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=dummy])
AT_CHECK([ovs-appctl netdev-dummy/ip4addr br0 2.2.2.2/24], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 2.2.2.3/32 br0 pkt_mark=1], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 1.1.1.0/24 br0 2.2.2.10], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 1.1.2.0/24 br0 2.2.2.10 pkt_mark=2], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 1.1.3.0/24 br0 pkt_mark=3], [2], [], [dnl
Error while inserting route.
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/add 1.1.foo.bar/24 br0 2.2.2.10], [2], [], [dnl
Invalid 'ip/plen' parameter
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/add 2.2.2.4/24 br0 pkt_mark=baz], [2], [], [dnl
Invalid pkt_mark, IP gateway or src_ip
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/show | grep User | sort], [0], [dnl
User: 1.1.1.0/24 dev br0 GW 2.2.2.10 SRC 2.2.2.2
User: 1.1.2.0/24 MARK 2 dev br0 GW 2.2.2.10 SRC 2.2.2.2
User: 2.2.2.3/32 MARK 1 dev br0 SRC 2.2.2.2
])
AT_CHECK([ovs-appctl --format=json --pretty ovs/route/show], [0], [dnl
[[
  {
    "dst": "2.2.2.0",
    "local": true,
    "nexthops": [
      {
        "dev": "br0"}],
    "prefix": 24,
    "prefsrc": "2.2.2.2",
    "priority": 184,
    "user": false},
  {
    "dst": "1.1.1.0",
    "local": false,
    "nexthops": [
      {
        "dev": "br0",
        "gateway": "2.2.2.10"}],
    "prefix": 24,
    "prefsrc": "2.2.2.2",
    "priority": 152,
    "user": true},
  {
    "dst": "1.1.2.0",
    "local": false,
    "mark": 2,
    "nexthops": [
      {
        "dev": "br0",
        "gateway": "2.2.2.10"}],
    "prefix": 24,
    "prefsrc": "2.2.2.2",
    "priority": 152,
    "user": true},
  {
    "dst": "2.2.2.3",
    "local": false,
    "mark": 1,
    "nexthops": [
      {
        "dev": "br0"}],
    "prefix": 32,
    "prefsrc": "2.2.2.2",
    "priority": 160,
    "user": true}]]
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([appctl - route/add with src - ipv4])
AT_KEYWORDS([ovs_router])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=dummy])
AT_CHECK([ovs-appctl netdev-dummy/ip4addr br0 192.168.9.2/24], [0], [OK
])
AT_CHECK([ovs-appctl netdev-dummy/ip4addr br0 192.168.9.3/24], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 192.168.9.11/32 br0 src=192.168.9.3], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 192.168.10.12/32 br0 192.168.9.1 src=192.168.9.3], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 192.168.10.13/32 br0 192.168.9.1 pkt_mark=13 src=192.168.9.3], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 192.168.10.14/32 br0 192.168.9.1 pkt_mark=14 src=192.168.9.2], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 192.168.10.15/32 br0 192.168.9.1 src=foo.bar.9.200], [2], [], [dnl
Invalid pkt_mark, IP gateway or src_ip
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/add 192.168.10.16/32 br0 192.168.9.1 src=192.168.9.200], [2], [], [dnl
Error while inserting route.
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/add 192.168.10.17/32 br0 192.168.11.1 src=192.168.9.3], [2], [], [dnl
Error while inserting route.
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/add 192.168.10.18/32 br0 src=192.168.9.3], [2], [], [dnl
Error while inserting route.
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/show | grep User | grep 192.168.10 | sort], [0], [dnl
User: 192.168.10.12/32 dev br0 GW 192.168.9.1 SRC 192.168.9.3
User: 192.168.10.13/32 MARK 13 dev br0 GW 192.168.9.1 SRC 192.168.9.3
User: 192.168.10.14/32 MARK 14 dev br0 GW 192.168.9.1 SRC 192.168.9.2
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([appctl - route/add with src - ipv6])
AT_KEYWORDS([ovs_router])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=dummy])
AT_CHECK([ovs-appctl netdev-dummy/ip6addr br0 2001:db8:cafe::2/64], [0], [OK
])
AT_CHECK([ovs-appctl netdev-dummy/ip6addr br0 2001:db8:cafe::3/64], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 2001:db8:cafe::11/128 br0 src=2001:db8:cafe::3], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 2001:db8:beef::12/128 br0 2001:db8:cafe::1 src=2001:db8:cafe::3], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 2001:db8:beef::13/128 br0 2001:db8:cafe::1 pkt_mark=13 src=2001:db8:cafe::3], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 2001:db8:beef::14/128 br0 2001:db8:cafe::1 pkt_mark=14 src=2001:db8:cafe::2], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 2001:db8:beef::15/128 br0 2001:db8:cafe::1 src=foo:bar:2001:db8:cafe], [2], [], [dnl
Invalid pkt_mark, IP gateway or src_ip
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/add 2001:db8:beef::16/128 br0 2001:db8:cafe::1 src=2001:db8:cafe::200], [2], [], [dnl
Error while inserting route.
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/add 2001:db8:beef::17/128 br0 2001:db8:face::1 src=2001:db8:cafe::3], [2], [], [dnl
Error while inserting route.
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/add 2001:db8:beef::18/128 br0 src=2001:db8:cafe::3], [2], [], [dnl
Error while inserting route.
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl ovs/route/show | grep User | grep 2001:db8:beef | sort], [0], [dnl
User: 2001:db8:beef::12/128 dev br0 GW 2001:db8:cafe::1 SRC 2001:db8:cafe::3
User: 2001:db8:beef::13/128 MARK 13 dev br0 GW 2001:db8:cafe::1 SRC 2001:db8:cafe::3
User: 2001:db8:beef::14/128 MARK 14 dev br0 GW 2001:db8:cafe::1 SRC 2001:db8:cafe::2
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([appctl - route/lookup])
AT_KEYWORDS([ovs_router])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=dummy])
AT_CHECK([ovs-appctl netdev-dummy/ip4addr br0 192.0.2.1/24], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 198.51.100.0/24 br0 192.0.2.254], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 192.0.2.1/24 br0 pkt_mark=123], [0], [OK
])

AT_CHECK([ovs-appctl ovs/route/add 198.51.100.200/24 br0 192.0.2.250 pkt_mark=1234], [0], [OK
])

AT_CHECK([ovs-appctl ovs/route/show | grep User | sort], [0], [User: 192.0.2.0/24 MARK 123 dev br0 SRC 192.0.2.1
User: 198.51.100.0/24 MARK 1234 dev br0 GW 192.0.2.250 SRC 192.0.2.1
User: 198.51.100.0/24 dev br0 GW 192.0.2.254 SRC 192.0.2.1
])

AT_CHECK([ovs-appctl ovs/route/lookup 198.51.100.1], [0], [src 192.0.2.1
gateway 192.0.2.254
dev br0
])

AT_CHECK([ovs-appctl ovs/route/lookup 198.51.100.1 pkt_mark=1234], [0], [src 192.0.2.1
gateway 192.0.2.250
dev br0
])
AT_CHECK([ovs-appctl ovs/route/del 198.51.100.0/24 pkt_mark=1234], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/show | grep User | sort], [0], [User: 192.0.2.0/24 MARK 123 dev br0 SRC 192.0.2.1
User: 198.51.100.0/24 dev br0 GW 192.0.2.254 SRC 192.0.2.1
])

OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([appctl - route/lookup6])
AT_KEYWORDS([ovs_router])
OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=dummy])
AT_CHECK([ovs-appctl netdev-dummy/ip6addr br0 2001:db8:cafe::1/64], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 2001:db8:babe::/64 br0 2001:db8:cafe::2], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/add 2001:db8:babe::/64 br0 2001:db8:cafe::3 pkt_mark=321], [0], [OK
])

AT_CHECK([ovs-appctl ovs/route/show | grep User | sort], [0], [dnl
User: 2001:db8:babe::/64 MARK 321 dev br0 GW 2001:db8:cafe::3 SRC 2001:db8:cafe::1
User: 2001:db8:babe::/64 dev br0 GW 2001:db8:cafe::2 SRC 2001:db8:cafe::1
])

AT_CHECK([ovs-appctl ovs/route/lookup 2001:db8:babe::1eaf], [0], [src 2001:db8:cafe::1
gateway 2001:db8:cafe::2
dev br0
])

AT_CHECK([ovs-appctl ovs/route/lookup 2001:db8:babe::1eaf pkt_mark=321], [0], [src 2001:db8:cafe::1
gateway 2001:db8:cafe::3
dev br0
])

AT_CHECK([ovs-appctl ovs/route/del 2001:db8:babe::/64 pkt_mark=321], [0], [OK
])
AT_CHECK([ovs-appctl ovs/route/show | grep User | sort], [0], [dnl
User: 2001:db8:babe::/64 dev br0 GW 2001:db8:cafe::2 SRC 2001:db8:cafe::1
])

OVS_VSWITCHD_STOP
AT_CLEANUP
