[pox-dev] Constructing 802.1q ethernet frames with POX's library
Murphy McCauley
murphy.mccauley at gmail.com
Wed Nov 20 12:58:49 PST 2013
On Nov 20, 2013, at 12:49 PM, Lucas Brasilino <lucas.brasilino at gmail.com> wrote:
> Hi!
>
> I'm about to develop a POX component that will deal with:
>
> 1) VLAN related header field (adding/removing/changing VLAN ID/PCP/EtherType)
>
> 2) Some bytes within L2 protocol payload (adding/removing/changing),
> but before L3 payload.
>
> By now I'm looking around item #1, using pox.lib.packet direct. I
> could not realise how can I set such VLAN's field. I did (from pox
> directory) using python interactively:
>
>>>> import pox.lib.packet as pkt
>
>>>> eth=pkt.ethernet(src="00:00:00:00:00:01",dst="00:00:00:00:00:02",type=pkt.ethernet.VLAN_TYPE)
>
>>>> vlan=pkt.vlan(id=10)
>
>>>> vlan.dump()
> '[VLAN vlan=10 pcp=0 ether=802.3/0000]'
>
>>>> ip=pkt.ipv4(srcip=IPAddr("10.0.0.1"),dstip=IPAddr("10.0.0.2"),protocol=pkt.ipv4.TCP_PROTOCOL)
>
>>>> eth.payload=ip
>>>> eth.dump()
> '[00:00:00:00:00:01>00:00:00:00:00:02 VLAN][IP+TCP 10.0.0.1>10.0.0.2
> (cs:00 v:4 hl:5 l:20 t:64)][0 bytes]'
>
> So, I'm not sure if this is the right path, but how can I 'add' vlan
> header object ('vlan' object) to the ethernet packet object ('eth'
> object)?
Should be more or less the same. As far as the packet library is concerned, Ethernet encapsulates VLAN and VLAN in turn encapsulates IP:
eth.payload = vlan
vlan.payload = ip
> By the way, is item #2 feasible ? How ?
Within the L2 payload but before the L3? Is this a custom protocol/packet type/encapsulation? If POX doesn't know it, it'll just result in the raw bytes being inserted into the chain of packet objects. You could either use this itself, or you could extend the packet library to understand it.
Note that all this is happening on the controller and not on the switch... I hope you're not planning to do such packet processing at a high rate.
-- Murphy
More information about the pox-dev
mailing list