@@ -37,6 +37,90 @@ let to_packetIn (pktIn : Core.packetIn) : AL.pktIn =
37
37
| { input_payload; total_len; port; reason } ->
38
38
(to_payload input_payload, total_len, Int32. of_int port, to_reason reason)
39
39
40
+ let to_pattern (p :Core.pattern ) : SDN_Types.Pattern.t =
41
+ let open SDN_Types.Pattern in
42
+ { dlSrc = p.Core. dlSrc
43
+ ; dlDst = p.Core. dlDst
44
+ ; dlTyp = p.Core. dlTyp
45
+ ; dlVlan = begin match p.Core. dlVlan with
46
+ | None -> None
47
+ | Some None -> Some (0xffff )
48
+ | Some vlan -> vlan
49
+ end
50
+ ; dlVlanPcp = p.Core. dlVlanPcp
51
+ ; nwSrc = begin match p.Core. nwSrc with
52
+ | None -> None
53
+ | Some ({ Core. m_value; Core. m_mask = None } ) ->
54
+ Some (m_value, 0l )
55
+ | Some ({ Core. m_value; Core. m_mask = Some (m ) } ) ->
56
+ Some (m_value, Int32. sub 32l m)
57
+ end
58
+ ; nwDst = begin match p.Core. nwDst with
59
+ | None -> None
60
+ | Some ({ Core. m_value; Core. m_mask = None } ) ->
61
+ Some (m_value, 0l )
62
+ | Some ({ Core. m_value; Core. m_mask = Some (m ) } ) ->
63
+ Some (m_value, Int32. sub 32l m)
64
+ end
65
+ ; nwProto = p.Core. nwProto
66
+ ; tpSrc = p.Core. tpSrc
67
+ ; tpDst = p.Core. tpDst
68
+ ; inPort = match p.Core. inPort with
69
+ | None -> None
70
+ | Some (n ) -> Some (Int32. of_int n)
71
+ }
72
+
73
+ let to_pseudoPort (in_port : Core.portId option ) pport =
74
+ let open Core in
75
+ match pport with
76
+ | PhysicalPort port ->
77
+ if Some port = in_port
78
+ then AL. InPort
79
+ else AL. Physical (Int32. of_int port)
80
+ | InPort -> AL. InPort
81
+ | Table -> AL. Table
82
+ | Normal -> AL. Normal
83
+ | Flood -> AL. Flood
84
+ | AllPorts -> AL. All
85
+ | Controller (buf ) -> AL. Controller (buf)
86
+ | Local -> AL. Local
87
+
88
+ let to_action (in_port : Core.portId option ) (act : Core.action ) : AL.action =
89
+ let open Core in
90
+ match act with
91
+ | Output pport -> AL. Output (to_pseudoPort in_port pport)
92
+ | SetDlVlan dlVlan -> AL. (Modify (SetVlan dlVlan))
93
+ | SetDlVlanPcp dlVlanPcp -> AL. (Modify (SetVlanPcp dlVlanPcp))
94
+ | SetDlSrc dlAddr -> AL. (Modify (SetEthSrc dlAddr))
95
+ | SetDlDst dlAddr -> AL. (Modify (SetEthDst dlAddr))
96
+ | SetNwSrc nwAddr -> AL. (Modify (SetIP4Src nwAddr))
97
+ | SetNwDst nwAddr -> AL. (Modify (SetIP4Dst nwAddr))
98
+ | SetNwTos nwTos -> AL. (Modify (SetIPProto nwTos))
99
+ | SetTpSrc tpPort -> AL. (Modify (SetTCPDstPort tpPort))
100
+ | SetTpDst tpPort -> AL. (Modify (SetTCPSrcPort tpPort))
101
+ | Enqueue _ -> assert false (* XXX(seliopou) raise an exception. It's not
102
+ possible to implement this without changing the types in SDN_Types. *)
103
+
104
+ let to_flowStats stats : SDN_Types.flowStats =
105
+ let open SDN_Types in
106
+ let open OpenFlow0x01_Stats in
107
+ let pattern = to_pattern stats.of_match in
108
+ let inPort = match pattern.Pattern. inPort with
109
+ | None -> None
110
+ | Some (x ) -> Some (from_portId x)
111
+ in
112
+ { flow_table_id = stats.table_id
113
+ ; flow_pattern = pattern
114
+ ; flow_duration_sec = stats.duration_sec
115
+ ; flow_duration_nsec = stats.duration_nsec
116
+ ; flow_priority = stats.priority
117
+ ; flow_idle_timeout = stats.idle_timeout
118
+ ; flow_hard_timeout = stats.hard_timeout
119
+ ; flow_actions = List. map (to_action inPort) stats.actions
120
+ ; flow_packet_count = stats.packet_count
121
+ ; flow_byte_count = stats.byte_count
122
+ }
123
+
40
124
let from_pattern (pat : AL.Pattern.t ) : Core.pattern =
41
125
{ Core. dlSrc = pat.AL.Pattern. dlSrc
42
126
; Core. dlDst = pat.AL.Pattern. dlDst
0 commit comments