Last active
August 29, 2015 14:16
-
-
Save arjunguha/ac9b0736e89762ffdcaf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Run this with utop *) | |
#require "core";; | |
(* NetKAT syntax using GADTs *) | |
open Core.Std | |
type switchId = Int64.t | |
type portId = Int32.t | |
type location = | |
| PhysicalPort of portId | |
| Pipe of string | |
| Query of string | |
type _ header = | |
| Switch : switchId header | |
| Location : location header | |
| IP4Src : Int32.t header | |
| IP4Dst : Int32.t header | |
type pred = | |
| True | |
| False | |
| Test : 'a header * 'a -> pred | |
| And of pred * pred | |
| Or of pred * pred | |
| Neg of pred | |
type pol = | |
| Filter of pred | |
| Mod : 'a header * 'a -> pol | |
| Union of pol * pol | |
| Seq of pol * pol | |
| Star of pol | |
| Link of switchId * portId * switchId * portId | |
(* This actually sucks. *) | |
type box = Box : 'a header -> box | |
let rec pol_fields (pol : pol) : box Set.Poly.t = match pol with | |
| Filter a -> Set.Poly.empty | |
| Mod (hdr, _) -> Set.Poly.singleton (Box hdr) | |
| Union (p, q) -> Set.Poly.union (pol_fields p) (pol_fields q) | |
| Seq (p, q) -> Set.Poly.union (pol_fields p) (pol_fields q) | |
| Star p -> pol_fields p | |
| Link _ -> Set.Poly.of_list [Box Switch; Box Location] | |
and pred_fields (pred : pred) : box Set.Poly.t = match pred with | |
| True -> Set.Poly.empty | |
| False -> Set.Poly.empty | |
| Test (hdr, _) -> Set.Poly.singleton (Box hdr) | |
| And (a, b) -> Set.Poly.union (pol_fields a) (pol_fields b) | |
| Or (a, b) -> Set.Poly.union (pol_fields a) (pol_fields b) | |
| Neg a -> pol_fields a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment