p4lang / tutorials

P4 language tutorials
Apache License 2.0
1.34k stars 881 forks source link

./mycontroler error #109

Closed qq995002966 closed 6 years ago

qq995002966 commented 6 years ago

Followed P4D2_2017_Fall/exercises/p4runtime/README, I tried to run ./mycontroller.py while got follow error message

Traceback (most recent call last):
  File "./mycontroller.py", line 179, in <module>
    main(args.p4info, args.bmv2_json)
  File "./mycontroller.py", line 124, in main    3             def describe(self):                                                                     
    s1 = p4runtime_lib.bmv2.Bmv2SwitchConnection('s1', address='127.0.0.1:50051')
  File "/usr/documents/p4lang/tutorials/P4D2_2017_Fall/exercises/p4runtime/p4runtime_lib/switch.py", line
 28, in __init__
    self.client_stub = p4runtime_pb2.P4RuntimeStub(self.channel)
AttributeError: 'module' object has no attribute 'P4RuntimeStub'

here is my pip list show

adium-theme-ubuntu (0.3
astroid (1.0.1)
Babel (2.5.1)
cffi (1.9.1)
crc16 (0.1.1)
ctypesgen (0.post125)
debtcollector (1.18.0)
enum-compat (0.0.2)
enum34 (1.1.6)
eventlet (0.20.0)
funcsigs (1.0.2)
futures (3.2.0)
greenlet (0.4.12)
grpcio (1.7.3)
ipaddr (2.1.10)
logilab-common (0.61.0)
mininet (2.2.2)
msgpack-python (0.4.8)
netaddr (0.7.19)
nnpy (0.1)
oslo.config (5.0.0)
oslo.i18n (3.18.0)
ovs (2.7.2)
p4-hlir (0.9.51)
p4-hlir-v1-1 (1.1.7)
p4c-bm (1.7.0-221c6198)
pbr (3.1.1)
pep8 (1.4.6)
pexpect (3.1)
pip (9.0.1)
ply (3.9)
protobuf (3.5.0.post1)
psutil (5.4.1)
ptf (0.9.1)
pycparser (2.17)pyflakes (0.8.1)
pylint (1.1.0)
pytz (2017.3)
PyYAML (3.12)
repoze.lru (0.7)
rfc3986 (1.1.0)
Routes (2.4.1)
ryu (4.19)
scapy (2.2.0)
setuptools (3.3)
six (1.10.0)
stevedore (1.27.1)Tenjin (1.1.1)
termcolor (1.1.0)
thrift (0.10.0)
tinyrpc (0.6)
unity-lens-photos (1.0)
virtualenv (15.1.0)
WebOb (1.7.3)
wheel (0.23.0)
wrapt (1.10.11)

and here is locate p4runtime_pb2 show

/usr/documents/p4lang/p4c/build/control-plane/p4/p4runtime_pb2.py
/usr/documents/p4lang/pi/proto/py_out/p4/p4runtime_pb2.py
/usr/documents/p4lang/pi/proto/py_out/p4/p4runtime_pb2_grpc.py
/usr/local/lib/python2.7/dist-packages/p4/p4runtime_pb2.py
/usr/local/lib/python2.7/dist-packages/p4/p4runtime_pb2.pyc
/usr/local/lib/python2.7/dist-packages/p4/p4runtime_pb2.pyo

do I miss some prerequisites ?

qq995002966 commented 6 years ago

Can anybody help? I'm still struggling with this problem. (╥╯^╰╥)

keesjank commented 6 years ago

Did you try the VM yet? That worked for me.

This is in the VM:

p4@p4:~ $ pip list astroid (1.4.4) cffi (1.11.2) chardet (2.3.0) crcmod (1.7) defer (1.0.6) enum34 (1.1.6) futures (3.1.1) grpcio (1.7.0) ipaddr (2.1.11) lazy-object-proxy (1.2.1) logilab-common (1.1.0) mininet (2.3.0d1) nnpy (0.1) pexpect (4.0.1) pip (8.1.1) protobuf (3.4.0) psutil (3.4.2) ptyprocess (0.5) pycparser (2.18) pyflakes (1.1.0) pygobject (3.20.0) pylint (1.5.2) pysqlite (2.7.0) python-apt (1.1.0b1) python-debian (0.1.27) pyxdg (0.25) scapy (2.2.0) setuptools (20.7.0) six (1.10.0) thrift (0.9.2) wrapt (1.8.0) You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. p4@p4:~ $ locate p4runtime_pb2 /home/vagrant/PI/proto/py_out/p4/p4runtime_pb2.py /home/vagrant/PI/proto/py_out/p4/p4runtime_pb2_grpc.py /home/vagrant/p4c/build/control-plane/p4/p4runtime_pb2.py /usr/local/lib/python2.7/dist-packages/p4/p4runtime_pb2.py /usr/local/lib/python2.7/dist-packages/p4/p4runtime_pb2.pyc /usr/local/lib/python2.7/dist-packages/p4/p4runtime_pb2.pyo p4@p4:~ $

bocon13 commented 6 years ago

It seems like you were missing the grpc python plugin at the time that p4runtime_pb.py was generated. You may still be missing it. You can try re-running make && sudo make install && sudo ldconfig inside your PI directory.

You might also want to bring up the tutorial VM via Vagrant, and then compare your environment to the VM environment.

tomyhu1995 commented 6 years ago

I stick on the same problem for a few days. I “solved” it by using tutorial VM via Vagrant.

qq995002966 commented 6 years ago

@tomyhu1995 hi tomyhu I also move to the VM following /P4D2_2017_Fall/exercises/README. May I ask you how to

Log in with username p4and password p4 and issue the command sudo shutdown -r now ?

I mean after vagrant up I got a virtualbox window, then I enter p4 , p4 but got Login incorrect like the picture show.

tomyhu1995 commented 6 years ago

@qq995002966 Hi

It is weird. I can log in by using username p4 and password p4.

BUT, I got the same problem when I opened the VM at the very first time. After a few hours, I could log in with username p4 and password p4. WEIRD!!

I don't know the reason why I can log in after waiting a few hours. But it proves that username and password are all correct.

Hope that my experience can help you.

qq995002966 commented 6 years ago

User p4 is added in root-bootstrap.sh

useradd -m -d /home/p4 -s /bin/bash p4
echo "p4:p4" | chpasswd
echo "p4 ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/99_p4
chmod 440 /etc/sudoers.d/99_p4
usermod -aG vboxsf p4

So bacause of the vagrant provision failure, I cannot login in vm with user p4.


Solution for vagrant provision failure:

I'm not familar with virtualbox, so I create a new ubuntu 16.04 server using Vmware. To access ubuntu archives from chain, I installed shadowsocks and proxychains-ng (because of some f***king government policy). After that, I run root-bootstrap.sh and user-bootstrap.sh manually. If you are in chain too and don't want to install shadowsocks for the extra work and low network speed, you could contact me to get a packaged vm image. Thanks guys.