Thanks so much Victor for your help.
Your code fixes my problem.

2016-01-21 4:35 GMT-08:00 Victor Orlikowski <[email protected]>:

> On Jan 21, 2016, at 5:33 AM, David Gabriel <[email protected]> wrote:
>
>
> I am getting an error when I want to get the *vlan id* of packets.
> In fact, I am using the following code I found here
> <http://ryu-zhdoc.readthedocs.org/en/latest/library_packet.html>
>
>     pkt = packet.Packet(array.array('B', ev.msg.data))
>     for p in pkt:
>         print p.protocol_name, p
>         if p.protocol_name == 'vlan':
>             print 'vid = ', p.vid
>
> However I get the following error:
>
> switch= Switch<dpid=52235646558, Port<dpid=52235646558, port_no=2, LIVE> >
> ethernet
> ethernet(dst='01:00:0c:cc:cc:cd',ethertype=50,src='68:bd:ab:80:2b:94')
> llc
> llc(control=ControlFormatU(modifier_function1=0,modifier_function2=0,pf_bit=0),dsap_addr=170,ssap_addr=170)
> hub: uncaught exception: Traceback (most recent call last):
>   File "/home/ubuntu/ryu/ryu/lib/hub.py", line 52, in _launch
>     func(*args, **kwargs)
>   File "/home/ubuntu/ryu/ryu/base/app_manager.py", line 459, in _event_loop
>     handler(ev)
>   File "/home/ubuntu/Documents/simpleSwitchv2.py", line 125, in
> _packet_in_handler
>     print p.protocol_name, p
> AttributeError: 'array.array' object has no attribute 'protocol_name'
>
>
> Don’t swaddle your message in an array; a Packet-In message should only
> ever contain (at maximum) one ethernet frame.
> The frame may not even be a complete frame, due to buffering; from the OF
> 1.4.0 switch spec:
>
> “The data fi eld contains the packet itself, or a fraction of the packet
> if the packet is bu ffered.”
>
> Your code *should* look something like this example adapted from
> rest_router:
>
> pkt = packet.Packet(msg.data)
> header_list = dict((p.protocol_name, p)
>                            for p in pkt.protocols if type(p) != str)
> if header_list:
>     if 'vlan' in header_list:
>         print 'vid = ' . header_list[‘vlan’].vid
>
> Best,
> Victor
> --
> Victor J. Orlikowski <> vjo@[cs.]duke.edu
>
>
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to