Skip to content

Commit adb4b10

Browse files
committed
Delete TableFeatures module
use of TableFeature instead (with appropriate function)
1 parent a17cdea commit adb4b10

File tree

3 files changed

+58
-103
lines changed

3 files changed

+58
-103
lines changed

lib/OpenFlow0x04.ml

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,11 +4300,11 @@ module TableFeature = struct
43004300

43014301
type t = tableFeatures
43024302

4303-
let sizeof (tf : tableFeatures) =
4303+
let sizeof (tf : t) =
43044304
(* should be equal to tf.length *)
43054305
pad_to_64bits (sizeof_ofp_table_features + sum (map TableFeatureProp.sizeof tf.feature_prop))
43064306

4307-
let marshal (buf : Cstruct.t) (tf : tableFeatures) : int =
4307+
let marshal (buf : Cstruct.t) (tf : t) : int =
43084308
set_ofp_table_features_length buf tf.length;
43094309
set_ofp_table_features_table_id buf tf.table_id;
43104310
set_ofp_table_features_pad (Cstruct.to_string (Cstruct.create 5)) 0 buf;
@@ -4316,7 +4316,7 @@ module TableFeature = struct
43164316
sizeof_ofp_table_features + (
43174317
marshal_fields (Cstruct.shift buf sizeof_ofp_table_features) tf.feature_prop TableFeatureProp.marshal)
43184318

4319-
let parse (bits : Cstruct.t) : tableFeatures*Cstruct.t =
4319+
let parse (bits : Cstruct.t) : t =
43204320
let length = get_ofp_table_features_length bits in
43214321
let tableId = get_ofp_table_features_table_id bits in
43224322
let name = Cstruct.to_string (get_ofp_table_features_name bits) in
@@ -4332,9 +4332,9 @@ module TableFeature = struct
43324332
metadata_write = metadataWrite;
43334333
config = config;
43344334
max_entries = maxEntries;
4335-
feature_prop = featureProp},(Cstruct.shift bits length)
4335+
feature_prop = featureProp}
43364336

4337-
let to_string (tf : tableFeatures) =
4337+
let to_string (tf : t) =
43384338
Format.sprintf "{ table_id = %u; name = %s; metadata_match = %Lu; \
43394339
metadata_write = %Lu; config = %s; max_entries = %lu;
43404340
feature_prop = %s }"
@@ -4346,35 +4346,9 @@ module TableFeature = struct
43464346
tf.max_entries
43474347
("[ " ^ (String.concat "; " (map TableFeatureProp.to_string tf.feature_prop)) ^ " ]")
43484348

4349-
end
4350-
4351-
module TableFeatures = struct
4352-
4353-
type t = tableFeatures list
4354-
4355-
let sizeof (tfr : tableFeatures list) =
4356-
sum (map TableFeature.sizeof tfr)
4357-
4358-
let marshal (buf : Cstruct.t) (tfr : tableFeatures list) =
4359-
marshal_fields buf tfr TableFeature.marshal
4360-
4361-
4362-
let rec parse_fields (bits : Cstruct.t) len cumul : tableFeatures list*Cstruct.t =
4363-
if len = cumul then [],bits
4364-
else (
4365-
let field,nextBits = TableFeature.parse bits in
4366-
let fields,bits3 = parse_fields nextBits len (cumul + (TableFeature.sizeof field)) in
4367-
(List.append [field] fields,bits3)
4368-
)
4369-
4370-
let parse (bits : Cstruct.t) : tableFeatures list =
4371-
let length = Cstruct.len bits in
4372-
let body,_ = parse_fields bits length 0 in
4373-
body
4374-
4375-
let to_string tfr =
4376-
"[ " ^ (String.concat "\n" (map TableFeature.to_string tfr)) ^ " ]"
4377-
4349+
let length_func (buf : Cstruct.t) : int option =
4350+
if Cstruct.len buf < sizeof_ofp_table_features then None
4351+
else Some (get_ofp_table_features_length buf)
43784352
end
43794353

43804354
module MultipartReq = struct
@@ -4425,7 +4399,7 @@ module MultipartReq = struct
44254399
| MeterStatsReq _ | MeterConfReq _ -> sizeof_ofp_meter_multipart_request
44264400
| TableFeatReq tfr -> (match tfr with
44274401
| None -> 0
4428-
| Some t -> TableFeatures.sizeof t)
4402+
| Some t -> sum (map TableFeature.sizeof t))
44294403
| ExperimentReq _ -> sizeof_ofp_experimenter_multipart_header)
44304404

44314405
let to_string (mpr : multipartRequest) : string =
@@ -4450,7 +4424,7 @@ module MultipartReq = struct
44504424
| MeterConfReq m -> Format.sprintf "MeterConf Req %lu" m
44514425
| MeterFeatReq -> "MeterFeat Req"
44524426
| TableFeatReq t-> Format.sprintf "TableFeat Req %s" (match t with
4453-
| Some v -> TableFeatures.to_string v
4427+
| Some v -> "[ " ^ (String.concat "; " (map TableFeature.to_string v)) ^ " ]"
44544428
| None -> "None" )
44554429
| ExperimentReq e-> Format.sprintf "Experimenter Req: id: %lu; type: %lu" e.exp_id e.exp_type)
44564430

@@ -4487,7 +4461,7 @@ module MultipartReq = struct
44874461
| TableFeatReq t ->
44884462
(match t with
44894463
| None -> 0
4490-
| Some v -> size + (TableFeatures.marshal pay_buf v))
4464+
| Some v -> size + marshal_fields pay_buf v TableFeature.marshal)
44914465
| ExperimentReq _ -> size
44924466

44934467
let parse (bits : Cstruct.t) : multipartRequest =
@@ -4520,7 +4494,7 @@ module MultipartReq = struct
45204494
| Some OFPMP_TABLE_FEATURES -> TableFeatReq (
45214495
if Cstruct.len bits <= sizeof_ofp_multipart_request then None
45224496
else Some (
4523-
TableFeatures.parse (Cstruct.shift bits sizeof_ofp_multipart_request)
4497+
parse_fields (Cstruct.shift bits sizeof_ofp_multipart_request) TableFeature.parse TableFeature.length_func
45244498
))
45254499
| Some OFPMP_EXPERIMENTER -> ExperimentReq (
45264500
let exp_bits = Cstruct.shift bits sizeof_ofp_multipart_request in
@@ -5383,7 +5357,7 @@ module MultipartReply = struct
53835357
| FlowStatsReply fsr -> sum (map FlowStats.sizeof fsr)
53845358
| AggregateReply ag -> AggregateStats.sizeof ag
53855359
| TableReply tr -> sum (map TableStats.sizeof tr)
5386-
| TableFeaturesReply tf -> TableFeatures.sizeof tf
5360+
| TableFeaturesReply tf -> sum (map TableFeature.sizeof tf)
53875361
| PortStatsReply psr -> sum (map PortStats.sizeof psr)
53885362
| QueueStatsReply qsr -> sum (map QueueStats.sizeof qsr)
53895363
| GroupStatsReply gs -> sum (map GroupStats.sizeof gs)
@@ -5400,7 +5374,7 @@ module MultipartReply = struct
54005374
| FlowStatsReply fsr -> Format.sprintf "Flow { %s }" (String.concat "; " (map FlowStats.to_string fsr))
54015375
| AggregateReply ag -> Format.sprintf "Aggregate Flow %s" (AggregateStats.to_string ag)
54025376
| TableReply tr -> Format.sprintf "TableReply { %s }" (String.concat "; " (map TableStats.to_string tr))
5403-
| TableFeaturesReply tf -> Format.sprintf "TableFeaturesReply %s" (TableFeatures.to_string tf)
5377+
| TableFeaturesReply tf -> Format.sprintf "TableFeaturesReply { %s }" (String.concat "; " (map TableFeature.to_string tf))
54045378
| PortStatsReply psr -> Format.sprintf "PortStatsReply { %s }" (String.concat "; " (map PortStats.to_string psr))
54055379
| QueueStatsReply qsr -> Format.sprintf "QueueStats { %s }" (String.concat "; " (map QueueStats.to_string qsr))
54065380
| GroupStatsReply gs -> Format.sprintf "GroupStats { %s }" (String.concat "; " (map GroupStats.to_string gs))
@@ -5434,7 +5408,7 @@ module MultipartReply = struct
54345408
marshal_fields ofp_body_bits tr TableStats.marshal
54355409
| TableFeaturesReply tf ->
54365410
set_ofp_multipart_reply_typ buf (ofp_multipart_types_to_int OFPMP_TABLE_FEATURES);
5437-
TableFeatures.marshal ofp_body_bits tf
5411+
marshal_fields ofp_body_bits tf TableFeature.marshal
54385412
| PortStatsReply psr ->
54395413
set_ofp_multipart_reply_typ buf (ofp_multipart_types_to_int OFPMP_PORT_STATS);
54405414
marshal_fields ofp_body_bits psr PortStats.marshal
@@ -5475,7 +5449,7 @@ module MultipartReply = struct
54755449
| Some OFPMP_TABLE ->
54765450
TableReply (parse_fields ofp_body_bits TableStats.parse TableStats.length_func)
54775451
| Some OFPMP_TABLE_FEATURES ->
5478-
TableFeaturesReply (TableFeatures.parse ofp_body_bits)
5452+
TableFeaturesReply (parse_fields ofp_body_bits TableFeature.parse TableFeature.length_func)
54795453
| Some OFPMP_PORT_STATS ->
54805454
PortStatsReply (parse_fields ofp_body_bits PortStats.parse PortStats.length_func)
54815455
| Some OFPMP_QUEUE ->

quickcheck/Arbitrary_OpenFlow0x04.ml

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ end
766766
module MultipartReq = struct
767767
open Gen
768768
open OpenFlow0x04_Core
769-
module TableFeatures = struct
769+
module TableFeature = struct
770770
module TableFeatureProp = struct
771771

772772
type t = TableFeatureProp.t
@@ -798,7 +798,7 @@ module MultipartReq = struct
798798
ret_gen PushPbbHdr;
799799
ret_gen PopPbbHdr;
800800
ret_gen SetMplsTtlHdr;
801-
ret_gen DecMplsTtlHdr;
801+
ret_gen DecMplsTtlHdr;
802802
ret_gen SetQueueHdr;
803803
arbitrary_uint32 >>= (fun n -> ret_gen (ExperimenterAHdr n))
804804
]
@@ -825,53 +825,39 @@ module MultipartReq = struct
825825
let size_of = TableFeatureProp.sizeof
826826
end
827827

828-
module TableFeature = struct
829-
type t = TableFeature.t
828+
type t = TableFeature.t
830829

831-
let arbitrary_config =
832-
ret_gen Deprecated
830+
let arbitrary_config =
831+
ret_gen Deprecated
833832

834-
let calc_length tfp =
835-
(* sizeof_ofp_table_feature = 64*)
836-
ret_gen (64+sum (List.map TableFeatureProp.size_of tfp))
833+
let calc_length tfp =
834+
(* sizeof_ofp_table_feature = 64*)
835+
ret_gen (64+sum (List.map TableFeatureProp.size_of tfp))
837836

838-
let arbitrary =
839-
arbitrary_uint8 >>= fun table_id ->
840-
arbitrary_stringN 32 >>= fun name ->
841-
arbitrary_uint64 >>= fun metadata_match ->
842-
arbitrary_uint64 >>= fun metadata_write ->
843-
arbitrary_config >>= fun config ->
844-
arbitrary_uint32 >>= fun max_entries ->
845-
list1 TableFeatureProp.arbitrary >>= fun feature_prop ->
846-
calc_length feature_prop>>= fun length ->
847-
ret_gen {
848-
length;
849-
table_id;
850-
name;
851-
metadata_match;
852-
metadata_write;
853-
config;
854-
max_entries;
855-
feature_prop
856-
}
857-
858-
let marshal = TableFeature.marshal
859-
let parse bits=
860-
let p,_ = TableFeature.parse bits in
861-
p
862-
let to_string = TableFeature.to_string
863-
let size_of = TableFeature.sizeof
864-
end
865-
866-
type t = TableFeatures.t
867-
868-
let arbitrary =
869-
list1 TableFeature.arbitrary >>= fun v ->
870-
ret_gen v
871-
let marshal = TableFeatures.marshal
872-
let parse = TableFeatures.parse
873-
let to_string = TableFeatures.to_string
874-
let size_of = TableFeatures.sizeof
837+
let arbitrary =
838+
arbitrary_uint8 >>= fun table_id ->
839+
arbitrary_stringN 32 >>= fun name ->
840+
arbitrary_uint64 >>= fun metadata_match ->
841+
arbitrary_uint64 >>= fun metadata_write ->
842+
arbitrary_config >>= fun config ->
843+
arbitrary_uint32 >>= fun max_entries ->
844+
list1 TableFeatureProp.arbitrary >>= fun feature_prop ->
845+
calc_length feature_prop>>= fun length ->
846+
ret_gen {
847+
length;
848+
table_id;
849+
name;
850+
metadata_match;
851+
metadata_write;
852+
config;
853+
max_entries;
854+
feature_prop
855+
}
856+
857+
let marshal = TableFeature.marshal
858+
let parse = TableFeature.parse
859+
let to_string = TableFeature.to_string
860+
let size_of = TableFeature.sizeof
875861
end
876862

877863
module FlowRequest = struct
@@ -918,7 +904,7 @@ module MultipartReq = struct
918904
let arbitrary_option =
919905
frequency [
920906
(1, ret_gen None);
921-
(3, TableFeatures.arbitrary >>= (fun v -> ret_gen (Some v)))
907+
(3, list1 TableFeature.arbitrary >>= (fun v -> ret_gen (Some v)))
922908
]
923909

924910
let arbitrary_type =

test/Test.ml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,16 @@ module RoundTripping = struct
323323
(openflow_quickCheck GenGroupMod.arbitrary
324324
GenGroupMod.to_string GenGroupMod.parse GenGroupMod.marshal)
325325

326-
TEST "OpenFlow0x04 MultipartReq.TableFeatures.TableFeatureProp RoundTrip" =
327-
let module GenTableFeatureProp = Gen0x04.OpenFlow0x04_Unsize(Gen0x04.MultipartReq.TableFeatures.TableFeatureProp) in
326+
TEST "OpenFlow0x04 MultipartReq.TableFeature.TableFeatureProp RoundTrip" =
327+
let module GenTableFeatureProp = Gen0x04.OpenFlow0x04_Unsize(Gen0x04.MultipartReq.TableFeature.TableFeatureProp) in
328328
(openflow_quickCheck GenTableFeatureProp.arbitrary
329329
GenTableFeatureProp.to_string GenTableFeatureProp.parse GenTableFeatureProp.marshal)
330330

331-
TEST "OpenFlow0x04 MultipartReq.TableFeatures.TableFeature RoundTrip" =
332-
let module GenTableFeature = Gen0x04.OpenFlow0x04_Unsize(Gen0x04.MultipartReq.TableFeatures.TableFeature) in
331+
TEST "OpenFlow0x04 MultipartReq.TableFeature RoundTrip" =
332+
let module GenTableFeature = Gen0x04.OpenFlow0x04_Unsize(Gen0x04.MultipartReq.TableFeature) in
333333
(openflow_quickCheck GenTableFeature.arbitrary
334334
GenTableFeature.to_string GenTableFeature.parse GenTableFeature.marshal)
335335

336-
TEST "OpenFlow0x04 MultipartReq.TableFeatures RoundTrip" =
337-
let module GenTableFeatureReq = Gen0x04.OpenFlow0x04_Unsize(Gen0x04.MultipartReq.TableFeatures) in
338-
(openflow_quickCheck GenTableFeatureReq.arbitrary
339-
GenTableFeatureReq.to_string GenTableFeatureReq.parse GenTableFeatureReq.marshal)
340-
341336
TEST "OpenFlow0x04 MultipartReq.FlowRequest RoundTrip" =
342337
let module GenTableFlowReq = Gen0x04.OpenFlow0x04_Unsize(Gen0x04.MultipartReq.FlowRequest) in
343338
(openflow_quickCheck GenTableFlowReq.arbitrary
@@ -442,11 +437,11 @@ module RoundTripping = struct
442437
let module GenPacketIn = Gen0x04.OpenFlow0x04_Unsize(Gen0x04.PacketIn) in
443438
(openflow_quickCheck GenPacketIn.arbitrary
444439
GenPacketIn.to_string GenPacketIn.parse GenPacketIn.marshal)
445-
446-
TEST "OpenFlow0x04 RoleRequest RoundTrip" =
447-
let module GenRoleReq = Gen0x04.OpenFlow0x04_Unsize(Gen0x04.RoleRequest) in
448-
(openflow_quickCheck GenRoleReq.arbitrary
449-
GenRoleReq.to_string GenRoleReq.parse GenRoleReq.marshal)
440+
441+
TEST "OpenFlow0x04 RoleRequest RoundTrip" =
442+
let module GenRoleReq = Gen0x04.OpenFlow0x04_Unsize(Gen0x04.RoleRequest) in
443+
(openflow_quickCheck GenRoleReq.arbitrary
444+
GenRoleReq.to_string GenRoleReq.parse GenRoleReq.marshal)
450445

451446
TEST "OpenFlow0x04 SwitchConfig RoundTrip" =
452447
let module GenSwitchConfig = Gen0x04.OpenFlow0x04_Unsize(Gen0x04.SwitchConfig) in

0 commit comments

Comments
 (0)