AT_BANNER([OpenFlow utilities])

AT_SETUP([encoding hellos])
dnl All versions up to a max version supported:
AT_CHECK([ovs-ofctl encode-hello 0x2], [0], [dnl
00000000  01 00 00 08 00 00 00 01
OFPT_HELLO (xid=0x1):
 version bitmap: 0x01
])
AT_CHECK([ovs-ofctl encode-hello 0x6], [0], [dnl
00000000  02 00 00 08 00 00 00 01
OFPT_HELLO (OF1.1) (xid=0x1):
 version bitmap: 0x01, 0x02
])
AT_CHECK([ovs-ofctl encode-hello 0xe], [0], [dnl
00000000  03 00 00 08 00 00 00 01
OFPT_HELLO (OF1.2) (xid=0x1):
 version bitmap: 0x01, 0x02, 0x03
])
AT_CHECK([ovs-ofctl encode-hello 0x1e], [0], [dnl
00000000  04 00 00 08 00 00 00 01
OFPT_HELLO (OF1.3) (xid=0x1):
 version bitmap: 0x01, 0x02, 0x03, 0x04
])
AT_CHECK([ovs-ofctl encode-hello 0x3e], [0], [dnl
00000000  05 00 00 08 00 00 00 01
OFPT_HELLO (OF1.4) (xid=0x1):
 version bitmap: 0x01, 0x02, 0x03, 0x04, 0x05
])

dnl Some versions below max version missing.
AT_CHECK([ovs-ofctl encode-hello 0xc], [0], [dnl
00000000  03 00 00 10 00 00 00 01-00 01 00 08 00 00 00 0c
OFPT_HELLO (OF1.2) (xid=0x1):
 version bitmap: 0x02, 0x03
])
AT_CHECK([ovs-ofctl encode-hello 0xa], [0], [dnl
00000000  03 00 00 10 00 00 00 01-00 01 00 08 00 00 00 0a
OFPT_HELLO (OF1.2) (xid=0x1):
 version bitmap: 0x01, 0x03
])
AT_CHECK([ovs-ofctl encode-hello 0x8], [0], [dnl
00000000  03 00 00 10 00 00 00 01-00 01 00 08 00 00 00 08
OFPT_HELLO (OF1.2) (xid=0x1):
 version bitmap: 0x03
])
AT_CHECK([ovs-ofctl encode-hello 0x4], [0], [dnl
00000000  02 00 00 10 00 00 00 01-00 01 00 08 00 00 00 04
OFPT_HELLO (OF1.1) (xid=0x1):
 version bitmap: 0x02
])
AT_CLEANUP

AT_SETUP([parsing key-value pairs])
dnl Key-only basics.
AT_CHECK([ovs-ofctl parse-key-value a a,b 'a b' 'a	b' 'a
b'], 0, [a
a, b
a, b
a, b
a, b
])

dnl Key-value basics.
AT_CHECK([ovs-ofctl parse-key-value a:b a=b a:b,c=d 'a=b c' 'a(b)' 'a(b),c(d)'], 0,
[a=b
a=b
a=b, c=d
a=b, c
a=b
a=b, c=d
])

dnl Values that contain nested delimiters.
AT_CHECK([ovs-ofctl parse-key-value 'a:(b,c)' 'a:b(c,d)e' 'a(b,c(d,e),f)'], 0,
[a=(b,c)
a=b(c,d)e
a=b,c(d,e),f
])

dnl Extraneous delimiters.
AT_CHECK([ovs-ofctl parse-key-value a,,b ',a  b' ' a b ,'], 0, [a, b
a, b
a, b
])

dnl Missing right parentheses.
dnl
dnl m4 can't handle unbalanced parentheses so we use @{:@, which
dnl Autotest replaces by a left parenthesis.
AT_CHECK([ovs-ofctl parse-key-value 'a@{:@b' 'a@{:@b(c)' 'a=b@{:@c'], 0, [a=b
a=b(c)
a=b@{:@c
])
AT_CLEANUP
