Skip to content

Commit 901b8cd

Browse files
committed
AsyncConfig change :
use bitmap to represent the accepted reason (previous implementation was an misunderstanding of the spec)
1 parent 0b42e32 commit 901b8cd

File tree

4 files changed

+127
-47
lines changed

4 files changed

+127
-47
lines changed

lib/OpenFlow0x04.ml

Lines changed: 87 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6636,6 +6636,75 @@ end
66366636

66376637
module AsyncConfig = struct
66386638

6639+
module PacketIn = struct
6640+
type t = packetInReasonMap
6641+
6642+
let to_string (t : t) =
6643+
Format.sprintf "{ table_miss = %B; apply_action = %B; invalid_ttl = %B }"
6644+
t.table_miss
6645+
t.apply_action
6646+
t.invalid_ttl
6647+
6648+
let marshal (t : t) : int8 =
6649+
(if t.table_miss then 1 lsl 0 else 0) lor
6650+
(if t.apply_action then 1 lsl 1 else 0) lor
6651+
(if t.invalid_ttl then 1 lsl 2 else 0)
6652+
6653+
let parse bits : t =
6654+
{ table_miss = test_bit16 0 bits
6655+
; apply_action = test_bit16 1 bits
6656+
; invalid_ttl = test_bit16 2 bits}
6657+
6658+
end
6659+
6660+
module PortStatus = struct
6661+
6662+
type t = portReasonMap
6663+
6664+
let to_string (t : t) =
6665+
Format.sprintf "{ add = %B; delete = %B; modify = %B }"
6666+
t.add
6667+
t.delete
6668+
t.modify
6669+
6670+
let marshal (t : t) : int8 =
6671+
(if t.add then 1 lsl 0 else 0) lor
6672+
(if t.delete then 1 lsl 1 else 0) lor
6673+
(if t.modify then 1 lsl 2 else 0)
6674+
6675+
let parse bits : t =
6676+
{ add = test_bit16 0 bits
6677+
; delete = test_bit16 1 bits
6678+
; modify = test_bit16 2 bits }
6679+
6680+
end
6681+
6682+
module FlowRemoved = struct
6683+
6684+
type t = flowReasonMask
6685+
6686+
let to_string (t : t) =
6687+
Format.sprintf "{ idle_timeout = %B; hard_timeout = %B; delete = %B; \
6688+
group_delete = %B }"
6689+
t.idle_timeout
6690+
t.hard_timeout
6691+
t.delete
6692+
t.group_delete
6693+
6694+
let marshal (t : t) : int8 =
6695+
(if t.idle_timeout then 1 lsl 0 else 0) lor
6696+
(if t.hard_timeout then 1 lsl 1 else 0) lor
6697+
(if t.delete then 1 lsl 2 else 0) lor
6698+
(if t.group_delete then 1 lsl 3 else 0)
6699+
6700+
let parse bits : t =
6701+
{ idle_timeout = test_bit16 0 bits
6702+
; hard_timeout = test_bit16 1 bits
6703+
; delete = test_bit16 2 bits
6704+
; group_delete = test_bit16 3 bits }
6705+
6706+
end
6707+
66396708
cstruct ofp_async_config {
66406709
uint32_t packet_in_mask0;
66416710
uint32_t packet_in_mask1;
@@ -6654,29 +6723,29 @@ module AsyncConfig = struct
66546723
Format.sprintf "{ packet_in reason (master/slave) = %s/%s; \
66556724
port_status reason (master/slave) = %s/%s; \
66566725
flow_removed reason (master/slave) = %s/%s }"
6657-
(PacketIn.Reason.to_string async.packet_in.m_master)
6658-
(PacketIn.Reason.to_string async.packet_in.m_slave)
6659-
(PortStatus.Reason.to_string async.port_status.m_master)
6660-
(PortStatus.Reason.to_string async.port_status.m_slave)
6661-
(FlowRemoved.RemovedReason.to_string async.flow_removed.m_master)
6662-
(FlowRemoved.RemovedReason.to_string async.flow_removed.m_slave)
6726+
(PacketIn.to_string async.packet_in.m_master)
6727+
(PacketIn.to_string async.packet_in.m_slave)
6728+
(PortStatus.to_string async.port_status.m_master)
6729+
(PortStatus.to_string async.port_status.m_slave)
6730+
(FlowRemoved.to_string async.flow_removed.m_master)
6731+
(FlowRemoved.to_string async.flow_removed.m_slave)
66636732

66646733
let marshal (buf : Cstruct.t) (async : asyncConfig) : int =
6665-
set_ofp_async_config_packet_in_mask0 buf (Int32.of_int (PacketIn.Reason.marshal async.packet_in.m_master));
6666-
set_ofp_async_config_packet_in_mask1 buf (Int32.of_int (PacketIn.Reason.marshal async.packet_in.m_slave));
6667-
set_ofp_async_config_port_status_mask0 buf (Int32.of_int (PortStatus.Reason.marshal async.port_status.m_master));
6668-
set_ofp_async_config_port_status_mask1 buf (Int32.of_int (PortStatus.Reason.marshal async.port_status.m_slave));
6669-
set_ofp_async_config_flow_removed_mask0 buf (Int32.of_int (FlowRemoved.RemovedReason.marshal async.flow_removed.m_master));
6670-
set_ofp_async_config_flow_removed_mask1 buf (Int32.of_int (FlowRemoved.RemovedReason.marshal async.flow_removed.m_slave));
6734+
set_ofp_async_config_packet_in_mask0 buf (Int32.of_int (PacketIn.marshal async.packet_in.m_master));
6735+
set_ofp_async_config_packet_in_mask1 buf (Int32.of_int (PacketIn.marshal async.packet_in.m_slave));
6736+
set_ofp_async_config_port_status_mask0 buf (Int32.of_int (PortStatus.marshal async.port_status.m_master));
6737+
set_ofp_async_config_port_status_mask1 buf (Int32.of_int (PortStatus.marshal async.port_status.m_slave));
6738+
set_ofp_async_config_flow_removed_mask0 buf (Int32.of_int (FlowRemoved.marshal async.flow_removed.m_master));
6739+
set_ofp_async_config_flow_removed_mask1 buf (Int32.of_int (FlowRemoved.marshal async.flow_removed.m_slave));
66716740
sizeof_ofp_async_config
66726741

66736742
let parse (bits : Cstruct.t) : asyncConfig =
6674-
let packet_in = { m_master = PacketIn.Reason.parse (Int32.to_int (get_ofp_async_config_packet_in_mask0 bits));
6675-
m_slave = PacketIn.Reason.parse (Int32.to_int (get_ofp_async_config_packet_in_mask1 bits))} in
6676-
let port_status = { m_master = PortStatus.Reason.parse (Int32.to_int (get_ofp_async_config_port_status_mask0 bits));
6677-
m_slave = PortStatus.Reason.parse (Int32.to_int (get_ofp_async_config_port_status_mask1 bits))} in
6678-
let flow_removed = { m_master = FlowRemoved.RemovedReason.parse (Int32.to_int (get_ofp_async_config_flow_removed_mask0 bits));
6679-
m_slave = FlowRemoved.RemovedReason.parse (Int32.to_int (get_ofp_async_config_flow_removed_mask1 bits))} in
6743+
let packet_in = { m_master = PacketIn.parse (Int32.to_int (get_ofp_async_config_packet_in_mask0 bits));
6744+
m_slave = PacketIn.parse (Int32.to_int (get_ofp_async_config_packet_in_mask1 bits))} in
6745+
let port_status = { m_master = PortStatus.parse (Int32.to_int (get_ofp_async_config_port_status_mask0 bits));
6746+
m_slave = PortStatus.parse (Int32.to_int (get_ofp_async_config_port_status_mask1 bits))} in
6747+
let flow_removed = { m_master = FlowRemoved.parse (Int32.to_int (get_ofp_async_config_flow_removed_mask0 bits));
6748+
m_slave = FlowRemoved.parse (Int32.to_int (get_ofp_async_config_flow_removed_mask1 bits))} in
66806749
{ packet_in; port_status; flow_removed }
66816750

66826751
end

lib/OpenFlow0x04_Core.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,13 @@ type element =
655655

656656
type helloElement = element list
657657

658-
type asyncConfig = { packet_in : packetInReason asyncMask;
659-
port_status : portReason asyncMask;
660-
flow_removed : flowReason asyncMask }
658+
type packetInReasonMap = { table_miss : bool; apply_action : bool; invalid_ttl : bool }
661659

660+
type portReasonMap = { add : bool; delete : bool; modify : bool }
661+
662+
type flowReasonMask = { idle_timeout : bool; hard_timeout : bool; delete : bool;
663+
group_delete : bool}
664+
665+
type asyncConfig = { packet_in : packetInReasonMap asyncMask;
666+
port_status : portReasonMap asyncMask;
667+
flow_removed : flowReasonMask asyncMask }

lib/OpenFlow0x04_Core.mli

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,14 @@ type element =
622622

623623
type helloElement = element list
624624

625-
type asyncConfig = { packet_in : packetInReason asyncMask;
626-
port_status : portReason asyncMask;
627-
flow_removed : flowReason asyncMask }
625+
type packetInReasonMap = { table_miss : bool; apply_action : bool; invalid_ttl : bool }
626+
627+
type portReasonMap = { add : bool; delete : bool; modify : bool }
628+
629+
type flowReasonMask = { idle_timeout : bool; hard_timeout : bool; delete : bool;
630+
group_delete : bool}
631+
632+
type asyncConfig = { packet_in : packetInReasonMap asyncMask;
633+
port_status : portReasonMap asyncMask;
634+
flow_removed : flowReasonMask asyncMask }
628635

quickcheck/Arbitrary_OpenFlow0x04.ml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,36 +1883,34 @@ module AsyncConfig = struct
18831883

18841884
type t = AsyncConfig.t
18851885

1886-
let arbitrary_FlowReason =
1887-
oneof [
1888-
ret_gen FlowIdleTimeout;
1889-
ret_gen FlowHardTiemout;
1890-
ret_gen FlowDelete;
1891-
ret_gen FlowGroupDelete]
1892-
1893-
let arbitrary_PacketInReason =
1894-
oneof [
1895-
ret_gen NoMatch;
1896-
ret_gen ExplicitSend;
1897-
ret_gen InvalidTTL
1898-
]
1899-
1900-
let arbitrary_PortStatusReason =
1901-
oneof [
1902-
ret_gen PortAdd;
1903-
ret_gen PortDelete;
1904-
ret_gen PortModify
1905-
]
1886+
let arbitrary_packetInReasonMap =
1887+
arbitrary_bool >>= fun table_miss ->
1888+
arbitrary_bool >>= fun apply_action ->
1889+
arbitrary_bool >>= fun invalid_ttl ->
1890+
ret_gen { table_miss; apply_action; invalid_ttl }
1891+
1892+
let arbitrary_portStatusReasonMap =
1893+
arbitrary_bool >>= fun add ->
1894+
arbitrary_bool >>= fun delete ->
1895+
arbitrary_bool >>= fun modify ->
1896+
ret_gen { add; delete; modify }
1897+
1898+
let arbitrary_flowRemovedReasonMap =
1899+
arbitrary_bool >>= fun idle_timeout ->
1900+
arbitrary_bool >>= fun hard_timeout ->
1901+
arbitrary_bool >>= fun delete ->
1902+
arbitrary_bool >>= fun group_delete ->
1903+
ret_gen { idle_timeout; hard_timeout; delete; group_delete }
19061904

19071905
let arbitrary_mask arb =
19081906
arb >>= fun m_master ->
19091907
arb >>= fun m_slave ->
19101908
ret_gen { m_master; m_slave }
19111909

19121910
let arbitrary =
1913-
arbitrary_mask arbitrary_PacketInReason >>= fun packet_in ->
1914-
arbitrary_mask arbitrary_PortStatusReason >>= fun port_status ->
1915-
arbitrary_mask arbitrary_FlowReason >>= fun flow_removed ->
1911+
arbitrary_mask arbitrary_packetInReasonMap >>= fun packet_in ->
1912+
arbitrary_mask arbitrary_portStatusReasonMap >>= fun port_status ->
1913+
arbitrary_mask arbitrary_flowRemovedReasonMap >>= fun flow_removed ->
19161914
ret_gen { packet_in; port_status; flow_removed }
19171915

19181916
let marshal = AsyncConfig.marshal

0 commit comments

Comments
 (0)