Skip to content

Commit f1d06cd

Browse files
committed
Table Features Instruction only parse the header
1 parent 2c06cbe commit f1d06cd

File tree

4 files changed

+116
-14
lines changed

4 files changed

+116
-14
lines changed

lib/OpenFlow0x04.ml

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,6 +3835,79 @@ module QueueRequest = struct
38353835

38363836
end
38373837

3838+
module InstructionTyp = struct
3839+
3840+
let sizeof (ins : instructionTyp) =
3841+
match ins with
3842+
| GotoTableTyp
3843+
| ApplyActionsTyp
3844+
| WriteActionsTyp
3845+
| WriteMetadataTyp
3846+
| ClearTyp
3847+
| MeterTyp -> 4
3848+
| ExperimenterTyp _ -> 8
3849+
3850+
let to_string (ins : instructionTyp) =
3851+
match ins with
3852+
| GotoTableTyp -> "Go to Table"
3853+
| ApplyActionsTyp -> "Apply Actions"
3854+
| WriteActionsTyp -> "Write Actions"
3855+
| WriteMetadataTyp -> "WriteMeta"
3856+
| ClearTyp -> "Clear"
3857+
| MeterTyp -> "Meter"
3858+
| ExperimenterTyp e -> Format.sprintf "Experimenter = %lu" e
3859+
3860+
let marshal (buf : Cstruct.t) (ins : instructionTyp) : int =
3861+
match ins with
3862+
| GotoTableTyp ->
3863+
set_ofp_instruction_typ buf (ofp_instruction_type_to_int OFPIT_GOTO_TABLE);
3864+
set_ofp_instruction_len buf 4;
3865+
sizeof_ofp_instruction
3866+
| ApplyActionsTyp ->
3867+
set_ofp_instruction_typ buf (ofp_instruction_type_to_int OFPIT_APPLY_ACTIONS);
3868+
set_ofp_instruction_len buf 4;
3869+
sizeof_ofp_instruction
3870+
| WriteActionsTyp ->
3871+
set_ofp_instruction_typ buf (ofp_instruction_type_to_int OFPIT_WRITE_ACTIONS);
3872+
set_ofp_instruction_len buf 4;
3873+
sizeof_ofp_instruction
3874+
| WriteMetadataTyp ->
3875+
set_ofp_instruction_typ buf (ofp_instruction_type_to_int OFPIT_WRITE_METADATA);
3876+
set_ofp_instruction_len buf 4;
3877+
sizeof_ofp_instruction
3878+
| ClearTyp ->
3879+
set_ofp_instruction_typ buf (ofp_instruction_type_to_int OFPIT_CLEAR_ACTIONS);
3880+
set_ofp_instruction_len buf 4;
3881+
sizeof_ofp_instruction
3882+
| MeterTyp ->
3883+
set_ofp_instruction_typ buf (ofp_instruction_type_to_int OFPIT_METER);
3884+
set_ofp_instruction_len buf 4;
3885+
sizeof_ofp_instruction
3886+
| ExperimenterTyp e ->
3887+
set_ofp_instruction_typ buf (ofp_instruction_type_to_int OFPIT_EXPERIMENTER);
3888+
set_ofp_instruction_len buf 8;
3889+
set_ofp_instruction_experimenter_experimenter buf e;
3890+
sizeof_ofp_instruction_experimenter
3891+
3892+
let parse (bits : Cstruct.t) : instructionTyp =
3893+
let typ = int_to_ofp_instruction_type (get_ofp_instruction_typ bits) in
3894+
match typ with
3895+
| Some OFPIT_GOTO_TABLE -> GotoTableTyp
3896+
| Some OFPIT_APPLY_ACTIONS -> ApplyActionsTyp
3897+
| Some OFPIT_WRITE_ACTIONS -> WriteActionsTyp
3898+
| Some OFPIT_WRITE_METADATA -> WriteMetadataTyp
3899+
| Some OFPIT_CLEAR_ACTIONS -> ClearTyp
3900+
| Some OFPIT_METER -> MeterTyp
3901+
| Some OFPIT_EXPERIMENTER -> ExperimenterTyp (get_ofp_instruction_experimenter_experimenter bits)
3902+
| None -> raise (Unparsable (sprintf "malfomed typ"))
3903+
3904+
let length_func (buf : Cstruct.t) : int option =
3905+
if Cstruct.len buf < sizeof_ofp_instruction then None
3906+
else Some (get_ofp_instruction_len buf)
3907+
3908+
end
3909+
3910+
38383911
module TableFeatureProp = struct
38393912

38403913
cstruct ofp_table_feature_prop_experimenter {
@@ -3853,9 +3926,9 @@ module TableFeatureProp = struct
38533926
let sizeof tfp : int =
38543927
let size = sizeof_ofp_table_feature_prop_header + (match tfp with
38553928
| TfpInstruction ins ->
3856-
Instructions.sizeof ins
3929+
sum (map InstructionTyp.sizeof ins)
38573930
| TfpInstructionMiss ins ->
3858-
Instructions.sizeof ins
3931+
sum (map InstructionTyp.sizeof ins)
38593932
| TfpNextTable t ->
38603933
List.length t
38613934
| TfpNextTableMiss t ->
@@ -3893,10 +3966,10 @@ module TableFeatureProp = struct
38933966
(match tfp with
38943967
| TfpInstruction ins ->
38953968
set_ofp_table_feature_prop_header_typ buf (ofp_table_feature_prop_type_to_int OFPTFPT_INSTRUCTIONS);
3896-
Instructions.marshal buf_payload ins
3969+
marshal_fields buf_payload ins InstructionTyp.marshal
38973970
| TfpInstructionMiss ins ->
38983971
set_ofp_table_feature_prop_header_typ buf (ofp_table_feature_prop_type_to_int OFPTFPT_INSTRUCTIONS_MISS);
3899-
Instructions.marshal buf_payload ins
3972+
marshal_fields buf_payload ins InstructionTyp.marshal
39003973
| TfpNextTable t ->
39013974
set_ofp_table_feature_prop_header_typ buf (ofp_table_feature_prop_type_to_int OFPTFPT_NEXT_TABLES);
39023975
let marsh (buf : Cstruct.t) (id : uint8) : int =
@@ -3962,9 +4035,9 @@ module TableFeatureProp = struct
39624035
let tfpPayBits = Cstruct.sub bits sizeof_ofp_table_feature_prop_header (tfpLength - sizeof_ofp_table_feature_prop_header) in
39634036
match int_to_ofp_table_feature_prop_type tfpType with
39644037
| Some OFPTFPT_INSTRUCTIONS ->
3965-
TfpInstruction (Instructions.parse tfpPayBits)
4038+
TfpInstruction (parse_fields tfpPayBits InstructionTyp.parse InstructionTyp.length_func)
39664039
| Some OFPTFPT_INSTRUCTIONS_MISS ->
3967-
TfpInstructionMiss (Instructions.parse tfpPayBits)
4040+
TfpInstructionMiss (parse_fields tfpPayBits InstructionTyp.parse InstructionTyp.length_func)
39684041
| Some OFPTFPT_NEXT_TABLES ->
39694042
let ids,_ = parse_tables tfpPayBits (tfpLength - sizeof_ofp_table_feature_prop_header) in
39704043
TfpNextTable ids
@@ -4011,9 +4084,9 @@ module TableFeatureProp = struct
40114084
Format.sprintf "{ type = %s; len:%u }"
40124085
(match tfp with
40134086
| TfpInstruction i->
4014-
(Format.sprintf "Instructions %s" (Instructions.to_string i))
4087+
(Format.sprintf "Instructions [ %s ]" (String.concat "; " (map InstructionTyp.to_string i)))
40154088
| TfpInstructionMiss i->
4016-
(Format.sprintf "InstructionMiss %s" (Instructions.to_string i))
4089+
(Format.sprintf "InstructionMiss [ %s ]" (String.concat "; " (map InstructionTyp.to_string i)))
40174090
| TfpNextTable n->
40184091
(Format.sprintf "NextTable [ %s ]"
40194092
(String.concat "; " (map string_of_int n)))

lib/OpenFlow0x04_Core.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ type action =
297297

298298
type actionSequence = action list
299299

300+
type instructionTyp =
301+
| GotoTableTyp
302+
| ApplyActionsTyp
303+
| WriteActionsTyp
304+
| WriteMetadataTyp
305+
| ClearTyp
306+
| MeterTyp
307+
| ExperimenterTyp of int32
308+
300309
type instruction =
301310
| GotoTable of tableId
302311
| ApplyActions of actionSequence
@@ -486,8 +495,8 @@ type queueRequest = {port_number : portId; queue_id : int32}
486495
type experimenter = {exp_id : int32; exp_type : int32}
487496

488497
type tableFeatureProp =
489-
| TfpInstruction of instruction list
490-
| TfpInstructionMiss of instruction list
498+
| TfpInstruction of instructionTyp list
499+
| TfpInstructionMiss of instructionTyp list
491500
| TfpNextTable of tableId list
492501
| TfpNextTableMiss of tableId list
493502
| TfpWriteAction of action list

lib/OpenFlow0x04_Core.mli

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,15 @@ type action =
315315

316316
type actionSequence = action list
317317

318+
type instructionTyp =
319+
| GotoTableTyp
320+
| ApplyActionsTyp
321+
| WriteActionsTyp
322+
| WriteMetadataTyp
323+
| ClearTyp
324+
| MeterTyp
325+
| ExperimenterTyp of int32
326+
318327
type instruction =
319328
| GotoTable of tableId
320329
| ApplyActions of actionSequence
@@ -455,8 +464,8 @@ type queueRequest = {port_number : portId; queue_id : int32}
455464
type experimenter = {exp_id : experimenterId; exp_type : int32}
456465

457466
type tableFeatureProp =
458-
| TfpInstruction of instruction list
459-
| TfpInstructionMiss of instruction list
467+
| TfpInstruction of instructionTyp list
468+
| TfpInstructionMiss of instructionTyp list
460469
| TfpNextTable of tableId list
461470
| TfpNextTableMiss of tableId list
462471
| TfpWriteAction of action list

quickcheck/Arbitrary_OpenFlow0x04.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,22 @@ module MultipartReq = struct
770770
module TableFeatureProp = struct
771771

772772
type t = TableFeatureProp.t
773+
774+
let arbitrary_typ =
775+
oneof [
776+
ret_gen GotoTableTyp;
777+
ret_gen ApplyActionsTyp;
778+
ret_gen WriteActionsTyp;
779+
ret_gen WriteMetadataTyp;
780+
ret_gen ClearTyp;
781+
ret_gen MeterTyp;
782+
arbitrary_uint32 >>= (fun n -> ret_gen (ExperimenterTyp n))
783+
]
773784

774785
let arbitrary =
775786
oneof [
776-
Instructions.arbitrary >>= (fun n -> ret_gen (TfpInstruction n));
777-
Instructions.arbitrary >>= (fun n -> ret_gen (TfpInstructionMiss n));
787+
list1 arbitrary_typ >>= (fun n -> ret_gen (TfpInstruction n));
788+
list1 arbitrary_typ >>= (fun n -> ret_gen (TfpInstructionMiss n));
778789
arbitrary_list Action.arbitrary >>= (fun n -> ret_gen (TfpWriteAction n));
779790
arbitrary_list Action.arbitrary >>= (fun n -> ret_gen (TfpWriteActionMiss n));
780791
arbitrary_list Action.arbitrary >>= (fun n -> ret_gen (TfpApplyAction n));

0 commit comments

Comments
 (0)