frenetic-lang / frenetic

The Frenetic Programming Language and Runtime System
http://www.frenetic-lang.org/
Other
223 stars 51 forks source link

Unable to load global policies in frenetic shell #601

Closed ZhijiaCHEN closed 6 years ago

ZhijiaCHEN commented 6 years ago

I tried to use frenetic shell to load policies, but the shell crashed at \<location> => \<location>syntax. Please see the following simple routing policies for a linear topology with two switches.

Policy to load in frenetic shell:

(* This policy would crash frenetic shell *)
(filter ip4Dst = 10.0.0.2 and switch = 1; port:=2; (1@2 => 2@2); port:= 1)+
(filter ip4Dst = 10.0.0.1 and switch = 2; port:= 2; (2@2 => 2@1); port := 1)

(* This policy works fine *)
(*(filter ip4Dst = 10.0.0.2 and switch = 1; port:=2) +
(filter ip4Dst = 10.0.0.2 and switch = 2; port:=1) +
(filter ip4Dst = 10.0.0.1 and switch = 2; port:=2) +
(filter ip4Dst = 10.0.0.1 and switch = 1; port:=1)*)

Shell crash message:

frenetic> load rt.txt
(((pid 13458) (thread_id 0)) "2018-01-14 03:59:28.540971321Z"
 "unhandled exception in Async scheduler"
 ("unhandled exception"
  ((monitor.ml.Error (Frenetic_netkat__Syntax.Non_local)
    ("Raised at file \"src/lib/netkat/Local_compiler.ml\", line 123, characters 32-47"
     "Called from file \"src/lib/async/NetKAT_Controller.ml\", line 39, characters 11-53"
     "Called from file \"src/lib/async/Shell.ml\", line 302, characters 22-43"
     "Called from file \"src/lib/async/Shell.ml\", line 324, characters 30-48"
     "Re-raised at file \"parsing/location.ml\", line 450, characters 12-23"
     "Re-raised at file \"parsing/location.ml\", line 450, characters 12-23"
     "Re-raised at file \"parsing/location.ml\", line 450, characters 12-23"
     "Re-raised at file \"parsing/location.ml\", line 450, characters 12-23"
     "Re-raised at file \"parsing/location.ml\", line 450, characters 12-23"
     "Re-raised at file \"parsing/location.ml\", line 450, characters 12-23"
     "Called from file \"src/lib/async/Shell.ml\", line 329, characters 5-17"
     "Called from file \"src/deferred0.ml\", line 61, characters 64-69"
     "Called from file \"src/job_queue.ml\", line 159, characters 6-47"
     "Caught by monitor main"))
   ((pid 13458) (thread_id 3)))))
frenetic@sdnhubvm:~/src/frenetic/examples/virtual/big-switch$
jnfoster commented 6 years ago

That's because the file has a global policy but NetKAT is passing it to the local compiler, which is barfing ungracefully.

https://github.com/frenetic-lang/frenetic/blob/master/src/lib/async/NetKAT_Controller.ml#L39

I can think of several ways to resolve it such as invoking the global compiler, or checking that the policy is local so at least we give a nice error message. @smolkaj what do you think we should do?

ZhijiaCHEN commented 6 years ago

OK, then I think I should be able to load the policy by invoking global compiler manually.

smolkaj commented 6 years ago

Yes, the global and virtual compilers are not currently integrated with the shell. I like using the dump command:

frenetic dump global <file> --update-controller

The --update-controler flag allows you to push the resulting tables to the controller.

ZhijiaCHEN commented 6 years ago

I see, thanks for the instruction!

ZhijiaCHEN commented 6 years ago

I think it's better to give a new subject to this issue. I am changing it to "Unable to load global policies in frenetic shell". Please feel free to revise it if you have something to improve.

smolkaj commented 6 years ago

Thanks. By the way, I just added a --stdin flag to the dump command, see #602. Once this is merged in, you can write

frenetic dump global --update-controller --stdin "1@1=>2@2"
ZhijiaCHEN commented 6 years ago

That's cool! Thanks for your help.

smolkaj commented 6 years ago

This has been addressed by #604.