AT_BANNER([dpctl])

AT_SETUP([dpctl - add-dp del-dp])
OVS_VSWITCHD_START
AT_CHECK([ovs-appctl dpctl/add-dp dummy@br0])
AT_CHECK([ovs-appctl dpctl/add-dp dummy@br0], [2], [],
  [ovs-vswitchd: add_dp (File exists)
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl dpctl/del-dp dummy@br0])
AT_CHECK([ovs-appctl dpctl/del-dp dummy@br0], [2], [], [stderr])
AT_CHECK([sed 's/(.*)/(...)/' stderr], [0], [dnl
ovs-vswitchd: opening datapath (...)
ovs-appctl: ovs-vswitchd: server returned an error
])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([dpctl - add-if set-if del-if])
OVS_VSWITCHD_START([], [], [=override])
AT_CHECK([ovs-appctl dpctl/add-dp dummy@br0])
AT_CHECK([ovs-appctl dpctl/show dummy@br0], [0], [dnl
dummy@br0:
  lookups: hit:0 missed:0 lost:0
  flows: 0
  port 0: br0 (dummy-internal)
])
AT_CHECK([ovs-appctl dpctl/add-if dummy@br0 vif1.0,type=dummy,port_no=5])
AT_CHECK([ovs-appctl dpctl/show dummy@br0], [0], [dnl
dummy@br0:
  lookups: hit:0 missed:0 lost:0
  flows: 0
  port 0: br0 (dummy-internal)
  port 5: vif1.0 (dummy)
])
AT_CHECK([ovs-appctl dpctl/add-if dummy@br0 vif1.0,type=dummy], [2], [],
  [stderr])
AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
  [ovs-vswitchd: adding vif1.0 to dummy@br0 failed (...)
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl dpctl/set-if dummy@br0 vif1.0,port_no=5])
AT_CHECK([ovs-appctl dpctl/set-if dummy@br0 vif1.0,type=system], [2], [],
  [ovs-vswitchd: vif1.0: can't change type from dummy to system
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl dpctl/set-if dummy@br0 br0,type=dummy-internal], [0])
AT_CHECK([ovs-appctl dpctl/set-if dummy@br0 br0,type=internal], [2], [],
  [ovs-vswitchd: br0: can't change type from dummy-internal to internal
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl dpctl/del-if dummy@br0 vif1.0])
AT_CHECK([ovs-appctl dpctl/show dummy@br0], [0], [dnl
dummy@br0:
  lookups: hit:0 missed:0 lost:0
  flows: 0
  port 0: br0 (dummy-internal)
])
AT_CHECK([ovs-appctl dpctl/del-if dummy@br0 vif1.0], [2], [],
  [ovs-vswitchd: no port named vif1.0
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl dpctl/show dummy@br0], [0], [dnl
dummy@br0:
  lookups: hit:0 missed:0 lost:0
  flows: 0
  port 0: br0 (dummy-internal)
])
AT_CHECK([ovs-appctl dpctl/del-if dummy@br0 nonexistent], [2], [],
  [ovs-vswitchd: no port named nonexistent
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl dpctl/del-if dummy@br0 br0], [2], [], [stderr])
AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
  [ovs-vswitchd: deleting port br0 from dummy@br0 failed (...)
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl dpctl/del-dp dummy@br0])
AT_CHECK([ovs-appctl dpctl/del-if dummy@br0 br0], [2], [], [stderr])
AT_CHECK([sed 's/(.*)/(...)/' stderr], [0],
  [ovs-vswitchd: opening datapath (...)
ovs-appctl: ovs-vswitchd: server returned an error
])
OVS_VSWITCHD_STOP(["/dummy@br0: port_del failed/d
/dummy@br0: failed to add vif1.0 as port/d
/Dropped 1 log messages in last/d"])
AT_CLEANUP

AT_SETUP([dpctl - add/mod/del-flows])
OVS_VSWITCHD_START
AT_CHECK([ovs-appctl dpctl/add-dp dummy@br0])
AT_DATA([flows.txt], [dnl
in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x1234) 2
])
AT_CHECK([ovs-appctl dpctl/add-flows dummy@br0 flows.txt], [0], [dnl
])
AT_CHECK([ovs-appctl dpctl/dump-flows dummy@br0 | sort], [0], [dnl
flow-dump from the main thread:
recirc_id(0),in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x1234), packets:0, bytes:0, used:never, actions:2
])
AT_DATA([flows.txt], [dnl
in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x1234) 3
])
AT_CHECK([ovs-appctl dpctl/mod-flows dummy@br0 flows.txt], [0], [dnl
])
AT_CHECK([ovs-appctl dpctl/dump-flows dummy@br0 | sort], [0], [dnl
flow-dump from the main thread:
recirc_id(0),in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x1234), packets:0, bytes:0, used:never, actions:3
])
AT_DATA([flows.txt], [dnl
in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x1234)
])
AT_CHECK([ovs-appctl dpctl/del-flows dummy@br0 flows.txt], [0], [dnl
])
AT_CHECK([ovs-appctl dpctl/dump-flows dummy@br0 | sort], [0], [dnl
])
AT_DATA([flows.txt], [dnl
add in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x1234) 2
add in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:03),eth_type(0x1234) 2
add in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:04),eth_type(0x1234) 2
modify in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x1234) 1
delete in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:03),eth_type(0x1234)
])
AT_CHECK([ovs-appctl dpctl/add-flows dummy@br0 flows.txt], [0], [dnl
])
AT_CHECK([ovs-appctl dpctl/dump-flows dummy@br0 | sort], [0], [dnl
flow-dump from the main thread:
recirc_id(0),in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:02),eth_type(0x1234), packets:0, bytes:0, used:never, actions:1
recirc_id(0),in_port(1),eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:04),eth_type(0x1234), packets:0, bytes:0, used:never, actions:2
])
AT_CHECK([ovs-appctl dpctl/del-flows dummy@br0], [0], [dnl
])
AT_CHECK([ovs-appctl dpctl/dump-flows dummy@br0 | sort], [0], [dnl
])
AT_CHECK([ovs-appctl dpctl/del-dp dummy@br0])
OVS_VSWITCHD_STOP
AT_CLEANUP

AT_SETUP([dpctl - ct-set-limits ct-get-limits ct-del-limits])
OVS_VSWITCHD_START
AT_CHECK([ovs-appctl dpctl/ct-get-limits], [0], [default limit=0
])
AT_CHECK([ovs-appctl dpctl/ct-get-limits zone=], [0], [default limit=0
])
AT_CHECK([ovs-appctl dpctl/ct-get-limits zone=,], [0], [default limit=0
])
AT_CHECK([ovs-appctl dpctl/ct-get-limits zone=x], [2], [],
  [ovs-vswitchd: invalid zone (Invalid argument)
ovs-appctl: ovs-vswitchd: server returned an error
])
AT_CHECK([ovs-appctl dpctl/ct-del-limits zone=])
AT_CHECK([ovs-appctl dpctl/ct-set-limits zone=0,limit=0])
AT_CHECK([ovs-appctl dpctl/ct-get-limits zone=0], [0], [default limit=0
zone=0,limit=0,count=0
])
AT_CHECK([ovs-appctl dpctl/ct-del-limits zone=0])

OVS_VSWITCHD_STOP
AT_CLEANUP