Skip to content

Commit dd7361b

Browse files
committed
Table Features Action only parse the header
1 parent f1d06cd commit dd7361b

File tree

4 files changed

+224
-84
lines changed

4 files changed

+224
-84
lines changed

lib/OpenFlow0x04.ml

Lines changed: 177 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,27 +2379,6 @@ module Action = struct
23792379
| SetQueue _ -> sizeof_ofp_action_set_queue
23802380
| Experimenter _ -> sizeof_ofp_action_experimenter
23812381

2382-
let to_type t : actionTyp =
2383-
match (int_to_ofp_action_type t) with
2384-
| Some OFPAT_OUTPUT -> Output
2385-
| Some OFPAT_COPY_TTL_OUT -> CopyTTLOut
2386-
| Some OFPAT_COPY_TTL_IN -> CopyTTLIn
2387-
| Some OFPAT_SET_MPLS_TTL -> SetMPLSTTL
2388-
| Some OFPAT_DEC_MPLS_TTL -> DecMPLSTTL
2389-
| Some OFPAT_PUSH_VLAN -> PushVLAN
2390-
| Some OFPAT_POP_VLAN -> PopVLAN
2391-
| Some OFPAT_PUSH_MPLS -> PushMPLS
2392-
| Some OFPAT_POP_MPLS -> PopMPLS
2393-
| Some OFPAT_SET_QUEUE -> SetQueue
2394-
| Some OFPAT_GROUP -> Group
2395-
| Some OFPAT_SET_NW_TTL -> SetNWTTL
2396-
| Some OFPAT_DEC_NW_TTL -> DecNWTTL
2397-
| Some OFPAT_SET_FIELD -> SetField
2398-
| Some OFPAT_PUSH_PBB -> PushPBB
2399-
| Some OFPAT_POP_PBB -> PopPBB
2400-
| Some OFPAT_EXPERIMENTER -> Experimenter
2401-
| None -> failwith "None type"
2402-
24032382
let marshal (buf : Cstruct.t) (act : action) : int =
24042383
let size = sizeof act in
24052384
match act with
@@ -2528,27 +2507,27 @@ module Action = struct
25282507
size
25292508

25302509
let parse (bits : Cstruct.t) : action =
2531-
match to_type (get_ofp_action_header_typ bits) with
2532-
| Output -> Output (PseudoPort.make (get_ofp_action_output_port bits)
2533-
(get_ofp_action_output_max_len bits))
2534-
| Group -> Group (get_ofp_action_group_group_id bits)
2535-
| PushVLAN -> PushVlan
2536-
| PopVLAN -> PopVlan
2537-
| PushMPLS -> PushMpls
2538-
| PopMPLS -> PopMpls
2539-
| SetField -> let field,_ = Oxm.parse (
2540-
Cstruct.shift bits 4) in (*TEST BECAUSE OF WRONG OFFSET??*)
2541-
SetField (field)
2542-
| CopyTTLOut -> CopyTtlOut
2543-
| CopyTTLIn -> CopyTtlIn
2544-
| SetMPLSTTL -> SetMplsTtl (get_ofp_action_mpls_ttl_mpls_ttl bits)
2545-
| DecMPLSTTL -> DecMplsTtl
2546-
| SetQueue -> SetQueue (get_ofp_action_set_queue_queue_id bits)
2547-
| SetNWTTL -> SetNwTtl (get_ofp_action_nw_ttl_nw_ttl bits)
2548-
| DecNWTTL -> DecNwTtl
2549-
| PushPBB -> PushPbb
2550-
| PopPBB -> PopPbb
2551-
| Experimenter -> Experimenter (get_ofp_action_experimenter_experimenter bits)
2510+
match int_to_ofp_action_type (get_ofp_action_header_typ bits) with
2511+
| Some OFPAT_OUTPUT -> Output (PseudoPort.make (get_ofp_action_output_port bits) (get_ofp_action_output_max_len bits))
2512+
| Some OFPAT_COPY_TTL_OUT -> CopyTtlOut
2513+
| Some OFPAT_COPY_TTL_IN -> CopyTtlIn
2514+
| Some OFPAT_SET_MPLS_TTL -> SetMplsTtl (get_ofp_action_mpls_ttl_mpls_ttl bits)
2515+
| Some OFPAT_DEC_MPLS_TTL -> DecMplsTtl
2516+
| Some OFPAT_PUSH_VLAN -> PushVlan
2517+
| Some OFPAT_POP_VLAN -> PopVlan
2518+
| Some OFPAT_PUSH_MPLS -> PushMpls
2519+
| Some OFPAT_POP_MPLS -> PopMpls
2520+
| Some OFPAT_SET_QUEUE -> SetQueue (get_ofp_action_set_queue_queue_id bits)
2521+
| Some OFPAT_GROUP -> Group (get_ofp_action_group_group_id bits)
2522+
| Some OFPAT_SET_NW_TTL -> SetNwTtl (get_ofp_action_nw_ttl_nw_ttl bits)
2523+
| Some OFPAT_DEC_NW_TTL -> DecNwTtl
2524+
| Some OFPAT_SET_FIELD -> let field,_ = Oxm.parse (
2525+
Cstruct.shift bits 4) in
2526+
SetField (field)
2527+
| Some OFPAT_PUSH_PBB -> PushPbb
2528+
| Some OFPAT_POP_PBB -> PopPbb
2529+
| Some OFPAT_EXPERIMENTER -> Experimenter (get_ofp_action_experimenter_experimenter bits)
2530+
| None -> failwith "None type"
25522531

25532532
let rec parse_fields (bits : Cstruct.t) : sequence * Cstruct.t =
25542533
if Cstruct.len bits < sizeof_ofp_action_header then ([], bits)
@@ -3907,6 +3886,146 @@ module InstructionTyp = struct
39073886

39083887
end
39093888

3889+
module ActionTyp = struct
3890+
3891+
let sizeof (act : actionTyp) =
3892+
match act with
3893+
| OutputAct
3894+
| CopyTTLOut
3895+
| CopyTTLIn
3896+
| SetMPLSTTL
3897+
| DecMPLSTTL
3898+
| PushVLAN
3899+
| PopVLAN
3900+
| PushMPLS
3901+
| PopMPLS
3902+
| SetQueueAct
3903+
| GroupAct
3904+
| SetNWTTL
3905+
| DecNWTTL
3906+
| SetFieldAct
3907+
| PushPBB
3908+
| PopPBB -> 4
3909+
| ExperimenterAct _ -> 8
3910+
3911+
let to_string (act : actionTyp) =
3912+
match act with
3913+
| OutputAct -> "Output"
3914+
| CopyTTLOut -> "CopyTTLOut"
3915+
| CopyTTLIn -> "CopyTTLIn"
3916+
| SetMPLSTTL -> "SetMplsTtl"
3917+
| DecMPLSTTL -> "DecMplsTtl"
3918+
| PushVLAN -> "PushVlan"
3919+
| PopVLAN -> "PopVlan"
3920+
| PushMPLS -> "PushMpls"
3921+
| PopMPLS -> "PopMpls"
3922+
| SetQueueAct -> "SetQueue"
3923+
| GroupAct -> "Group"
3924+
| SetNWTTL -> "SetNwTtl"
3925+
| DecNWTTL -> "DecMplsTtl"
3926+
| SetFieldAct -> "SetField"
3927+
| PushPBB -> "PushPBB"
3928+
| PopPBB -> "PopPBB"
3929+
| ExperimenterAct e -> Format.sprintf "Experimenter = %lu" e
3930+
3931+
let marshal (buf : Cstruct.t) (act : actionTyp) : int =
3932+
match act with
3933+
| OutputAct ->
3934+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_OUTPUT);
3935+
set_ofp_action_header_len buf 4;
3936+
4 (* ofp_action_header without the padding *)
3937+
| CopyTTLOut ->
3938+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_COPY_TTL_OUT);
3939+
set_ofp_action_header_len buf 4;
3940+
4
3941+
| CopyTTLIn ->
3942+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_COPY_TTL_IN);
3943+
set_ofp_action_header_len buf 4;
3944+
4
3945+
| SetMPLSTTL ->
3946+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_SET_MPLS_TTL);
3947+
set_ofp_action_header_len buf 4;
3948+
4
3949+
| DecMPLSTTL ->
3950+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_DEC_MPLS_TTL);
3951+
set_ofp_action_header_len buf 4;
3952+
4
3953+
| PushVLAN ->
3954+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_PUSH_VLAN);
3955+
set_ofp_action_header_len buf 4;
3956+
4
3957+
| PopVLAN ->
3958+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_POP_VLAN);
3959+
set_ofp_action_header_len buf 4;
3960+
4
3961+
| PushMPLS ->
3962+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_PUSH_MPLS);
3963+
set_ofp_action_header_len buf 4;
3964+
4
3965+
| PopMPLS ->
3966+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_POP_MPLS);
3967+
set_ofp_action_header_len buf 4;
3968+
4
3969+
| SetQueueAct ->
3970+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_SET_QUEUE);
3971+
set_ofp_action_header_len buf 4;
3972+
4
3973+
| GroupAct ->
3974+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_GROUP);
3975+
set_ofp_action_header_len buf 4;
3976+
4
3977+
| SetNWTTL ->
3978+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_SET_NW_TTL);
3979+
set_ofp_action_header_len buf 4;
3980+
4
3981+
| DecNWTTL ->
3982+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_DEC_NW_TTL);
3983+
set_ofp_action_header_len buf 4;
3984+
4
3985+
| SetFieldAct ->
3986+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_SET_FIELD);
3987+
set_ofp_action_header_len buf 4;
3988+
4
3989+
| PushPBB ->
3990+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_PUSH_PBB);
3991+
set_ofp_action_header_len buf 4;
3992+
4
3993+
| PopPBB ->
3994+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_POP_PBB);
3995+
set_ofp_action_header_len buf 4;
3996+
4
3997+
| ExperimenterAct e ->
3998+
set_ofp_action_header_typ buf (ofp_action_type_to_int OFPAT_EXPERIMENTER);
3999+
set_ofp_action_header_len buf 8;
4000+
set_ofp_action_experimenter_experimenter buf e;
4001+
sizeof_ofp_action_experimenter
4002+
4003+
let parse (bits : Cstruct.t) : actionTyp =
4004+
match (int_to_ofp_action_type (get_ofp_action_header_typ bits)) with
4005+
| Some OFPAT_OUTPUT -> OutputAct
4006+
| Some OFPAT_COPY_TTL_OUT -> CopyTTLOut
4007+
| Some OFPAT_COPY_TTL_IN -> CopyTTLIn
4008+
| Some OFPAT_SET_MPLS_TTL -> SetMPLSTTL
4009+
| Some OFPAT_DEC_MPLS_TTL -> DecMPLSTTL
4010+
| Some OFPAT_PUSH_VLAN -> PushVLAN
4011+
| Some OFPAT_POP_VLAN -> PopVLAN
4012+
| Some OFPAT_PUSH_MPLS -> PushMPLS
4013+
| Some OFPAT_POP_MPLS -> PopMPLS
4014+
| Some OFPAT_SET_QUEUE -> SetQueueAct
4015+
| Some OFPAT_GROUP -> GroupAct
4016+
| Some OFPAT_SET_NW_TTL -> SetNWTTL
4017+
| Some OFPAT_DEC_NW_TTL -> DecNWTTL
4018+
| Some OFPAT_SET_FIELD -> SetFieldAct
4019+
| Some OFPAT_PUSH_PBB -> PushPBB
4020+
| Some OFPAT_POP_PBB -> PopPBB
4021+
| Some OFPAT_EXPERIMENTER -> ExperimenterAct (get_ofp_action_experimenter_experimenter bits)
4022+
| None -> failwith "None type"
4023+
4024+
let length_func (buf : Cstruct.t) : int option =
4025+
if Cstruct.len buf < 4 (* ofp_action_header without padding *) then None
4026+
else Some (get_ofp_action_header_len buf)
4027+
4028+
end
39104029

39114030
module TableFeatureProp = struct
39124031

@@ -3934,13 +4053,13 @@ module TableFeatureProp = struct
39344053
| TfpNextTableMiss t ->
39354054
List.length t
39364055
| TfpWriteAction act ->
3937-
sum (map Action.sizeof act)
4056+
sum (map ActionTyp.sizeof act)
39384057
| TfpWriteActionMiss act ->
3939-
sum (map Action.sizeof act)
4058+
sum (map ActionTyp.sizeof act)
39404059
| TfpApplyAction act ->
3941-
sum (map Action.sizeof act)
4060+
sum (map ActionTyp.sizeof act)
39424061
| TfpApplyActionMiss act ->
3943-
sum (map Action.sizeof act)
4062+
sum (map ActionTyp.sizeof act)
39444063
| TfpMatch ox ->
39454064
Oxm.sizeof_header ox
39464065
| TfpWildcard ox ->
@@ -3984,16 +4103,16 @@ module TableFeatureProp = struct
39844103
marshal_fields buf_payload t marsh
39854104
| TfpWriteAction act ->
39864105
set_ofp_table_feature_prop_header_typ buf (ofp_table_feature_prop_type_to_int OFPTFPT_WRITE_ACTIONS);
3987-
marshal_fields buf_payload act Action.marshal
4106+
marshal_fields buf_payload act ActionTyp.marshal
39884107
| TfpWriteActionMiss act ->
39894108
set_ofp_table_feature_prop_header_typ buf (ofp_table_feature_prop_type_to_int OFPTFPT_WRITE_ACTIONS_MISS);
3990-
marshal_fields buf_payload act Action.marshal
4109+
marshal_fields buf_payload act ActionTyp.marshal
39914110
| TfpApplyAction act ->
39924111
set_ofp_table_feature_prop_header_typ buf (ofp_table_feature_prop_type_to_int OFPTFPT_APPLY_ACTIONS);
3993-
marshal_fields buf_payload act Action.marshal
4112+
marshal_fields buf_payload act ActionTyp.marshal
39944113
| TfpApplyActionMiss act ->
39954114
set_ofp_table_feature_prop_header_typ buf (ofp_table_feature_prop_type_to_int OFPTFPT_APPLY_ACTIONS_MISS);
3996-
marshal_fields buf_payload act Action.marshal
4115+
marshal_fields buf_payload act ActionTyp.marshal
39974116
| TfpMatch ox ->
39984117
set_ofp_table_feature_prop_header_typ buf (ofp_table_feature_prop_type_to_int OFPTFPT_MATCH);
39994118
marshal_fields buf_payload ox Oxm.marshal_header
@@ -4045,13 +4164,13 @@ module TableFeatureProp = struct
40454164
let ids,_ = parse_tables tfpPayBits (tfpLength - sizeof_ofp_table_feature_prop_header) in
40464165
TfpNextTableMiss ids
40474166
| Some OFPTFPT_WRITE_ACTIONS ->
4048-
TfpWriteAction (Action.parse_sequence tfpPayBits)
4167+
TfpWriteAction (parse_fields tfpPayBits ActionTyp.parse ActionTyp.length_func)
40494168
| Some OFPTFPT_WRITE_ACTIONS_MISS ->
4050-
TfpWriteActionMiss (Action.parse_sequence tfpPayBits)
4169+
TfpWriteActionMiss (parse_fields tfpPayBits ActionTyp.parse ActionTyp.length_func)
40514170
| Some OFPTFPT_APPLY_ACTIONS ->
4052-
TfpApplyAction (Action.parse_sequence tfpPayBits)
4171+
TfpApplyAction (parse_fields tfpPayBits ActionTyp.parse ActionTyp.length_func)
40534172
| Some OFPTFPT_APPLY_ACTIONS_MISS ->
4054-
TfpApplyActionMiss (Action.parse_sequence tfpPayBits)
4173+
TfpApplyActionMiss (parse_fields tfpPayBits ActionTyp.parse ActionTyp.length_func)
40554174
| Some OFPTFPT_MATCH ->
40564175
let fields,_ = Oxm.parse_headers tfpPayBits in
40574176
TfpMatch fields
@@ -4095,16 +4214,16 @@ module TableFeatureProp = struct
40954214
(String.concat "; " (map string_of_int n)))
40964215
| TfpWriteAction a ->
40974216
(Format.sprintf "WriteAction [ %s ]"
4098-
(String.concat "; " (map Action.to_string a)))
4217+
(String.concat "; " (map ActionTyp.to_string a)))
40994218
| TfpWriteActionMiss a ->
41004219
(Format.sprintf "WriteActionMiss [ %s ]"
4101-
(String.concat "; " (map Action.to_string a)))
4220+
(String.concat "; " (map ActionTyp.to_string a)))
41024221
| TfpApplyAction a ->
41034222
(Format.sprintf "ApplyActions [ %s ]"
4104-
(String.concat "; " (map Action.to_string a)))
4223+
(String.concat "; " (map ActionTyp.to_string a)))
41054224
| TfpApplyActionMiss a ->
41064225
(Format.sprintf "ApplyActionsMiss [ %s ]"
4107-
(String.concat "; " (map Action.to_string a)))
4226+
(String.concat "; " (map ActionTyp.to_string a)))
41084227
| TfpMatch s ->
41094228
(Format.sprintf "Match [ %s ]"
41104229
(String.concat "; " (map Oxm.field_name s)))

lib/OpenFlow0x04_Core.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ type pseudoPort =
258258
| Any
259259

260260
type actionTyp =
261-
| Output
261+
| OutputAct
262262
| CopyTTLOut
263263
| CopyTTLIn
264264
| SetMPLSTTL
@@ -267,14 +267,14 @@ type actionTyp =
267267
| PopVLAN
268268
| PushMPLS
269269
| PopMPLS
270-
| SetQueue
271-
| Group
270+
| SetQueueAct
271+
| GroupAct
272272
| SetNWTTL
273273
| DecNWTTL
274-
| SetField
274+
| SetFieldAct
275275
| PushPBB
276276
| PopPBB
277-
| Experimenter
277+
| ExperimenterAct of int32
278278

279279
type action =
280280
| Output of pseudoPort
@@ -499,10 +499,10 @@ type tableFeatureProp =
499499
| TfpInstructionMiss of instructionTyp list
500500
| TfpNextTable of tableId list
501501
| TfpNextTableMiss of tableId list
502-
| TfpWriteAction of action list
503-
| TfpWriteActionMiss of action list
504-
| TfpApplyAction of action list
505-
| TfpApplyActionMiss of action list
502+
| TfpWriteAction of actionTyp list
503+
| TfpWriteActionMiss of actionTyp list
504+
| TfpApplyAction of actionTyp list
505+
| TfpApplyActionMiss of actionTyp list
506506
| TfpMatch of oxm list
507507
| TfpWildcard of oxm list
508508
| TfpWriteSetField of oxm list

lib/OpenFlow0x04_Core.mli

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ type pseudoPort =
275275
port (including flows with no output port). *)
276276

277277
type actionTyp =
278-
| Output
278+
| OutputAct
279279
| CopyTTLOut
280280
| CopyTTLIn
281281
| SetMPLSTTL
@@ -284,14 +284,14 @@ type actionTyp =
284284
| PopVLAN
285285
| PushMPLS
286286
| PopMPLS
287-
| SetQueue
288-
| Group
287+
| SetQueueAct
288+
| GroupAct
289289
| SetNWTTL
290290
| DecNWTTL
291-
| SetField
291+
| SetFieldAct
292292
| PushPBB
293293
| PopPBB
294-
| Experimenter
294+
| ExperimenterAct of int32
295295

296296
type action =
297297
| Output of pseudoPort
@@ -468,10 +468,10 @@ type tableFeatureProp =
468468
| TfpInstructionMiss of instructionTyp list
469469
| TfpNextTable of tableId list
470470
| TfpNextTableMiss of tableId list
471-
| TfpWriteAction of action list
472-
| TfpWriteActionMiss of action list
473-
| TfpApplyAction of action list
474-
| TfpApplyActionMiss of action list
471+
| TfpWriteAction of actionTyp list
472+
| TfpWriteActionMiss of actionTyp list
473+
| TfpApplyAction of actionTyp list
474+
| TfpApplyActionMiss of actionTyp list
475475
| TfpMatch of oxm list
476476
| TfpWildcard of oxm list
477477
| TfpWriteSetField of oxm list

0 commit comments

Comments
 (0)