-
Notifications
You must be signed in to change notification settings - Fork 4
/
SDN_Types.mli
220 lines (168 loc) · 6.01 KB
/
SDN_Types.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
(** A uniform interface to OpenFlow 1.0 and 1.3.
A high-level language, such as Frenetic, should support OpenFlow 1.0
and also exploit OpenFlow 1.3 features when possible. For example,
when two Frenetic actions are composed in parallel, they logically work
on two copies of a packet. Certain kinds of parallel composition cannot
be realized in OpenFlow 1.0, but they are trivial to implement with
group tables in OpenFlow 1.3.
Similarly, OpenFlow 1.3 can implement failover efficiently using fast-
failover groups. But, in OpenFlow 1.0, we have to incur a round-trip
to the controller.
Instead of creating two different versions of the Frenetic compiler, we
here define a high-level action data type. When targeting OpenFlow 1.0,
actions translates to 1.0 action sequences and controller round-trips
if needed. When targeting OpenFlow 1.3, action also builds group
tables to realize actions efficiently. This requires a global analysis
of all the actions in a flow table. Therefore, Frenetic needs to
supply the entire flow table at once and cannot add and remove flow table
entries individually *)
(** {1 OpenFlow Identifier Types}
OpenFlow requires identifiers for switches, ports, transaction numbers, etc.
The representation of these identifiers varies across different versions
of OpenFlow, which is why they are abstract.
*)
open Packet
type switchId = int64 with sexp
type portId = int32 with sexp
type queueId = int32 with sexp
type bufferId = int32 with sexp
exception Unsupported of string
(** {1 Packet Forwarding} *)
module Pattern : sig
module Ip : sig
type t = nwAddr * int32
(** [match_all] is pattern that matches any address *)
val match_all : t
(** [less_eq x1 x2] returns true when [x2] matches any address that [x1] will
match *)
val less_eq : t -> t -> bool
(** [eq p1 p2] returns true when [p1] and [p2] match the same set of
addresses *)
val eq : t -> t -> bool
(** [join p1 p2] is the least pattern [pm] such that [less_eq p1 pm] and
[less_eq p2 pm] *)
val join : t -> t -> t
(** [intersect x1 x2] returns the intersection of when [x1] and [x2] *)
val intersect : t -> t -> t option
(** [compatible x1 x2] returns true when [x1] and [x2] have a non-empty intersection *)
val compatible : t -> t -> bool
(** [ip_shift x] returns an [int32] after shifting [x] by its mask *)
val shift : t -> int32
val format : Format.formatter -> t -> unit
val string_of : t -> string
end
(** WARNING: There are dependencies between different fields that must be met *)
type t =
{ dlSrc : dlAddr option
; dlDst : dlAddr option
; dlTyp : dlTyp option
; dlVlan : dlVlan
; dlVlanPcp : dlVlanPcp option
; nwSrc : Ip.t option
; nwDst : Ip.t option
; nwProto : nwProto option
; tpSrc : tpPort option
; tpDst : tpPort option
; inPort : portId option }
(** [match_all] is pattern that matches any packet *)
val match_all : t
(** [less_eq p1 p2] returns true when [p2] matches any packet that [p1] will
match *)
val less_eq : t -> t -> bool
(** [eq p1 p2] returns true when [p1] and [p2] match the same set of packets *)
val eq : t -> t -> bool
(** [join p1 p2] is the least pattern [pm] such that [less_eq p1 pm] and
[less_eq p2 pm] *)
val join : t -> t -> t
val format : Format.formatter -> t -> unit
val string_of : t -> string
end
type modify =
| SetEthSrc of dlAddr
| SetEthDst of dlAddr
| SetVlan of dlVlan
| SetVlanPcp of dlVlanPcp
| SetEthTyp of dlTyp
| SetIPProto of nwProto
| SetIP4Src of nwAddr
| SetIP4Dst of nwAddr
| SetTCPSrcPort of tpPort
| SetTCPDstPort of tpPort
type pseudoport =
| Physical of portId
| InPort
| Table
| Normal
| Flood
| All
| Controller of int
| Local
type action =
| Output of pseudoport
| Enqueue of portId * queueId
| Modify of modify
type seq = action list
type par = seq list
type group = par list
type timeout =
| Permanent (** No timeout *)
| ExpiresAfter of int16 (** Time out after [n] seconds *)
type flow = {
pattern: Pattern.t;
action: group;
cookie: int64;
idle_timeout: timeout;
hard_timeout: timeout
}
(** Priorities are implicit *)
type flowTable = flow list
(** {1 Controller Packet Processing} *)
(** The payload for [packetIn] and [packetOut] messages *)
type payload =
| Buffered of bufferId * bytes
(** [Buffered (id, buf)] is a packet buffered on a switch *)
| NotBuffered of bytes
with sexp
(** [payload_bytes payload] returns the bytes for the given payload *)
val payload_bytes : payload -> bytes
type packetInReason =
| NoMatch
| ExplicitSend
(** [(payload, total_length, in_port, reason)] *)
type pktIn = payload * int * portId * packetInReason
(** [(payload, in_port option, action list)] *)
type pktOut = payload * (portId option) * (action list)
(* {1 Switch Configuration} *)
(** A simplification of the _switch features_ message from OpenFlow *)
type switchFeatures = {
switch_id : switchId;
switch_ports : portId list
}
(* {1 Statistics} *)
(** The body of a reply to an individual flow statistics request *)
type flowStats = {
flow_table_id : int8; (** ID of table flow came from *)
flow_pattern : Pattern.t;
flow_duration_sec: int32;
flow_duration_nsec: int32;
flow_priority: int16;
flow_idle_timeout: int16;
flow_hard_timeout: int16;
flow_actions: action list;
flow_packet_count: int64;
flow_byte_count: int64
}
(* {1 Errors} *)
(* TODO: FILL *)
(* {1 Pretty-printing } *)
val format_action : Format.formatter -> action -> unit
val format_seq : Format.formatter -> seq -> unit
val format_par : Format.formatter -> par -> unit
val format_group : Format.formatter -> group -> unit
val format_flow : Format.formatter -> flow -> unit
val format_flowTable : Format.formatter -> flowTable -> unit
val string_of_action : action -> string
val string_of_seq : seq -> string
val string_of_par : par -> string
val string_of_flow : flow -> string
val string_of_flowTable : ?label:string -> flowTable -> string