frenetic-lang / frenetic

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

<location> =>> <location> syntax unrecognized #596

Closed ZhijiaCHEN closed 6 years ago

ZhijiaCHEN commented 6 years ago

Hello, I downloaded the frenetic-tutorial-vm to try network virtualization examples in the virtual directory. But I wasn't able to run the run.sh in most examples such as diamond. It crashes with the following error:

frenetic@frenetic-tutorial-vm:~/src/frenetic/examples/virtual/diamond$ ./run.sh 
File "vtopo.kat", line 2, characters 8-8:
unexpected character in NetKAT expression: '>'

Raised at file "lib/Frenetic_NetKAT_Lexer.ml", line 164, characters 31-50
Called from file "frenetic/Dump.ml", line 224, characters 16-31
Called from file "src/command.ml", line 2340, characters 6-97
Called from file "src/exn.ml", line 90, characters 6-10
frenetic@frenetic-tutorial-vm:~/src/frenetic/examples/virtual/diamond$ 

It seems to me that the compiler dose not recognize the =>> syntax.

And for example that have no such problem, such as big-switch which only has a drop policy in vtopo.kat, executing run.sh outputs some files end with ".dot". If those files are the supposed result of running run.sh, could someone tell me what am I suppose to do with these files to run the example? Thanks!

smolkaj commented 6 years ago

Thanks for reporting this bug. I should be able to fix it today.

Regarding the .dot files, these are Graphviz files: https://graphviz.gitlab.io/. The run.sh script will automatically dump some graphs that are used internally by the virtual compiler. Likely they are not very meaningful to you, unless you have read our paper "A Fast Compiler for NetKAT". In any case, the script will automatically compile the .dot files to *.svg files (which you can then look at, e.g. with a web browser) given that you have graphviz installed, which you can do by running brew install graphviz on MacOS or apt-get install graphviz on Ubuntu.

smolkaj commented 6 years ago

Looks like the problem is simply that the frenetic-tutorial-vm is out of date. Things work fine for me:

steffen ~/src/frenetic-lang/frenetic/examples/virtual/diamond (master)$ ./run.sh 
[virtual] Statistics:
  |V(vgraph)|: 12
  |E(vgraph)|: 16
  |V(pgraph)|: 20
  |E(pgraph)|: 34
  |V(prod_graph)|: 45
  |E(prod_graph)|: 73
  |V(pruned_graph)|: 45
  |E(pruned_graph)|: 73
  |V(fabric_graph)|: 25
  |E(fabric_graph)|: 28

+--------------------------------+
| Switch 1 | Pattern | Action    |
|--------------------------------|
| InPort = 0         | Output(2) |
|--------------------------------|
|                    |           |
+--------------------------------+

+--------------------------------+
| Switch 2 | Pattern | Action    |
|--------------------------------|
| InPort = 1         | Output(3) |
|--------------------------------|
|                    |           |
+--------------------------------+

+---------------------------------------------+
| Switch 3 | Pattern | Action                 |
|---------------------------------------------|
| InPort = 2         | SetField(vlan, <none>) |
|                    | Output(0)              |
|---------------------------------------------|
|                    |                        |
+---------------------------------------------+

virtual compilation time: 0.0037
global compilation time: 0.0006
g_fabric
g_pruned
pg
vg
g_raw

@jnfoster: Do you know how to update the VM? If you point me in the right direction I can take care of it.

smolkaj commented 6 years ago

@ZhijiaCHEN: As a temporary workaround, you could just install the newest version of frenetic by hand, but this may require some basic familiarity with OCaml/opam. You need OCaml 4.05.0 (opam switch 4.05.0) and then it should be as easy running opam pin add frenetic . -y

ZhijiaCHEN commented 6 years ago

@smolkaj Thanks for your instruction! But my problem still exists. I guess I need to call opam to install frenetic, and run make in frenetic root dir after I switch to OCaml 4.05.0. And then I get dependency problems I have no idea how to solve. I think I'd better wait until you update the VM. In case you may be interested, I also quote the output when I run make and opam install frenetic.

 frenetic@frenetic-tutorial-vm:~/src/frenetic$ make
time -p jbuilder build @install
Error: External library "cohttp.async" is unavailable.
-> required by "src/lib/async/jbuild (context default)"
External library "cohttp.async" is not available because it depends on the following libraries that are not available:
- cohttp-async -> not found
Hint: try: jbuilder external-lib-deps --missing @install
Command exited with non-zero status 1
real 0.02
user 0.01
sys 0.00
Makefile:4: recipe for target 'build' failed
make: *** [build] Error 1
frenetic@frenetic-tutorial-vm:~/src/frenetic$ opam install cohttp
[NOTE] Package cohttp is already installed (current version is 1.0.2).
opam install -y frenetic

=-=- Synchronising pinned packages =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[frenetic] /home/frenetic/src/ synchronized
The following dependencies couldn't be met:
  - frenetic -> topology >= 0.4.0 -> packet >= 0.3.1 -> sexplib < 113.01.00
Your request can't be satisfied:
  - sexplib<113.01.00 is not available because your system doesn't comply with ocaml-version >= "4.02.1" & ocaml-version < "4.03".

No solution found, exiting
frenetic@frenetic-tutorial-vm:~/src/frenetic$ cd ~/src/frenetic/
jnfoster commented 6 years ago

@ZhijiaCHEN, did you try to install the missing libraries using the hint that OPAM gave you?

jbuilder external-lib-deps --missing @install
ZhijiaCHEN commented 6 years ago

@jnfoster, yes, but it complained about missing some packets that I have already installed. Please see the quoted output below. Thanks!

frenetic@frenetic-tutorial-vm:~/src/frenetic$ jbuilder external-lib-deps --missing @install
Error: The following libraries are missing in the default context:
- cohttp.async
- cstruct.async
- menhir
Hint: try: opam install cohttp cstruct menhir
frenetic@frenetic-tutorial-vm:~/src/frenetic$ opam install cohttp cstruct menhir
[NOTE] Package cohttp is already installed (current version is 1.0.2).
[NOTE] Package cstruct is already installed (current version is 3.2.1).
[NOTE] Package menhir is already installed (current version is 20171222).
smolkaj commented 6 years ago

@ZhijiaCHEN: Actually, if you use opam pin you shouldn't have to install any dependencies manually or run make by hand. Opam know how to do all this properly. Let me fill in some gaps in my in my instructions: 1) Run opam switch 4.05.0. 2) Make sure you're environment variables are set appropriately by running eval $(opam config env). 3) Navigate to the frenetic source folder. 4) Make sure you have checked out the latest version of frenetic: git checkout master && git pull. 5) Run opam pin add frenetic . -y in the frenetic source folder (or run opam pin add frenetic <frenetic-src-folder> -y)

ZhijiaCHEN commented 6 years ago

@smolkaj: Thank you for your detailed instructions. But actually I have gone through all these steps before. I just tried again by running your instructions literally, and it reported type error in Network.ml files. Here is the out put:

frenetic@frenetic-tutorial-vm:~/src/frenetic$ opam switch 4.05.0
frenetic@frenetic-tutorial-vm:~/src/frenetic$ eval $(opam config env)
frenetic@frenetic-tutorial-vm:~/src/frenetic$ git checkout master && git pull
Already on 'master'
Your branch is up-to-date with 'origin/master'.
Already up-to-date.
frenetic@frenetic-tutorial-vm:~/src/frenetic$ opam pin add frenetic . -y
[NOTE] Package frenetic is already path-pinned to /home/frenetic/src/frenetic.
       This will erase any previous custom definition.
Proceed ? [Y/n] y

[frenetic] /home/frenetic/src/frenetic/ synchronized
[frenetic] Installing new package description from /home/frenetic/src/frenetic

frenetic needs to be installed.
The following actions will be performed:
  ∗  install frenetic 4.2.0*

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[frenetic.4.2.0] /home/frenetic/src/frenetic/ already up-to-date

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[ERROR] The compilation of frenetic failed at "jbuilder build -p frenetic -j
        4".

#=== ERROR while installing frenetic.4.2.0 ====================================#
# opam-version 1.2.2
# os           linux
# command      jbuilder build -p frenetic -j 4
# path         /home/frenetic/.opam/4.05.0/build/frenetic.4.2.0
# compiler     4.05.0
# exit-code    1
# env-file     /home/frenetic/.opam/4.05.0/build/frenetic.4.2.0/frenetic-2585-05296d.env
# stdout-file  /home/frenetic/.opam/4.05.0/build/frenetic.4.2.0/frenetic-2585-05296d.out
# stderr-file  /home/frenetic/.opam/4.05.0/build/frenetic.4.2.0/frenetic-2585-05296d.err
### stderr ###
# [...]
# Warning 3: deprecated: VertexMap.add
# [since 2017-11] Use [set] instead
# File "src/lib/kernel/Network.ml", line 397, characters 22-35:
# Warning 3: deprecated: VertexMap.add
# [since 2017-11] Use [set] instead
# File "src/lib/kernel/Network.ml", line 587, characters 18-316:
# Error: This expression should not be a function, the expected type is
# 'a Core_kernel.Std.Array.t
# 
# Waiting for 2 jobs to finish.

=-=- Error report -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The following actions failed
  ∗  install frenetic 4.2.0
No changes have been performed
[NOTE] Pinning command successful, but your installed packages may be out of
       sync.
frenetic@frenetic-tutorial-vm:~/src/frenetic$ 

I also tried in another fresh frenetic tutorial VM in case that I might have messed up something, but the result turned out to be the same (the error message was flooded away by the installation message of other packages, so I didn't notice that yesterday).

smolkaj commented 6 years ago

Thanks for the details, @ZhijiaCHEN. The problem here is that JaneStreet released a new version of their library that makes some breaking changes.

Could you open frenetic.opam and replace the "core" entry in the depends: [ ... ] section with the following:

"core"   {>= "v0.9.0" & < "v0.10.0"}

This will force opam to use the correct version of the library.

(I will also soon push a patch to the master branch to prevent this error in the future.)

ZhijiaCHEN commented 6 years ago

@smolkaj: Great! That solves the problem. I am going to close this issue. Thanks for your help!

smolkaj commented 6 years ago

Glad it worked. No problem.

smolkaj commented 6 years ago

FYI, I have also pushed a patch to master: 8d7f300e05354ae5edbe53368aeb6e2a77dc0750