Hi all,

Just thought I would send this simple piece of code which generates an arp 
reply based on a request. Replace SRCMAC with whatever is appropriate.

Hope this avoids any more FEPs, and resolves at least one FABNAQ at the risk of 
creating an avalanche  Frequently Asked Questions That Never Existed Before 
(FAQTNEB). Oh dear... ;)

def send_arp_reply(self, dp, packet, port):
        arp_packet = arp()
        arp_packet.hwtype     = arp.HW_TYPE_ETHERNET
        arp_packet.prototype  = arp.PROTO_TYPE_IP
        arp_packet.hwsrc      = SRCMAC
        arp_packet.hwdst     = packet.next.hwsrc
        #Ethernet length
        arp_packet.hwlen      = 6
        arp_packet.opcode     = arp.REPLY
        #IPv4 length
        arp_packet.protolen   = 4
        arp_packet.protosrc   = packet.next.protodst
        arp_packet.protodst   = packet.next.protosrc
        #vlan_pac = vlan()
        #if you have vlan stuff (add a .next above)
        #vlan_pac.tos = packet.next.tos
        #vlan_pac.cfi = packet.next.cfi
        #vlan_pac.id = packet.next.id
        #vlan_pac.eth_type = packet.next.eth_type
        #vlan_pac.set_payload(arp_packet)
        eth = ethernet()
        eth.src        = SRCMAC
        eth.dst        = packet.next.hwsrc
        eth.type        = packet.type #ethernet.VLAN_TYPE
        eth.set_payload(arp_packet)
        self.send_openflow_packet(dp, eth.tostring(), [[openflow.OFPAT_OUTPUT, 
[0, port]]],openflow.OFPP_NONE)

On Feb 16, 2011, at 10:29 PM, kk yap wrote:

> Hi,
> 
> There are many ways to do this and none of this is particularly more
> appealing.  If you are using Python, you can try dpkt or scapy.
> Handcrafting it is not that bad for ARP either.  If you are using
> C/C++, I do not know of nice libraries to use here so anyone who has
> any idea can educate me too.
> 
> In general, you can craft all sort of packets in NOX and it is not
> clear than NOX is responsible for support that.
> 
> Regards
> KK
> 
> On 16 February 2011 13:20, Bob Lantz <[email protected]> wrote:
>> Generating ARPs in OpenFlow is a frequently encountered problem (a FEP?)!! 
>> And how to do so conveniently and correctly might be something of what I 
>> call a FABNAQ - a Frequently Asked But Never (or rarely adequately) Answered 
>> Question. (FABNAQs are great because they generate lots of Google results 
>> which don't actually answer the question.)
>> 
>> So, if you have working code to generate correct ARP replies, I think 
>> sending it to the list would be helpful for posterity!
>> 
>> Also, for NOX developers - what is the preferred easy way to generate ARP 
>> packets? If it's not simple or convenient, is there a way to make it more so?
>> 
>> -Bob
>> 
>> On Feb 16, 2011, at 12:18 PM, Niky Riga wrote:
>> 
>>> Hi Aaron,
>>> 
>>> that might not be an issue at all, but I don't see in your code where you 
>>> set the ethernet headers (basically the src and dst) for the arp reply.
>>> 
>>> If you want, I have some code that I wrote a while back to send arp 
>>> replies, that seemed to work as expected. I can forward it along if this is 
>>> helpful.
>>> 
>>> --niky
>>> 
>>> On 2/16/11 2:59 PM, Aaron Rosen wrote:
>>>> Hello,
>>>> 
>>>> I'm trying to send arp replies from my nox controller though for some
>>>> reason my packets don't seem to be getting sent out and I was hoping
>>>> someone could point out where I'm going wrong. This is the code I
>>>> have:
>>>> 
>>>>      if packet.type == ethernet.ARP_TYPE:
>>>>             arppacket = arp.arp(packet.next.arr, packet.next.prev)
>>>>             if arppacket.opcode == arppacket.REQUEST:
>>>>                 tmp_dst = arppacket.protodst
>>>>                 arppacket.protodst =  arppacket.protosrc
>>>>                 arppacket.protosrc =  tmp_dst
>>>>                 arppacket.hwdst = arppacket.hwsrc
>>>>                 arppacket.hwsrc = mac_to_int('\xd2\x85\xde\x8e\xf6\x13')
>>>>                 arppacket.opcode = arppacket.REPLY
>>>>                 packet.next = arppacket;
>>>>                 self.send_openflow(dpid, None, packet.arr,
>>>> openflow.OFPP_FLOOD, inport);
>>>>                 print "ARP REPLY SEND!!"
>>>>                 return CONTINUE
>>>> 
>>>> When I run tcpdump on the node that is sending the requests I does not
>>>> see any of these packets.
>>>> 
>>>> I'm trying to look at my openflow traffic with wireshark but for some
>>>> reason I'm not seeing any. Though at my controller I'm definitely
>>>> getting the packets. (I think this may because I'm using mininet? I've
>>>> tried all the interfaces on my machine in wireshark). Though when I
>>>> try this using the Openflow Tutorial provided VM i'm also not seeing
>>>> any 'of' packets in wireshark there? (Any idea why)?
>>>> 
>>>> Thanks,
>>>> 
>>>> Aaron
>>>> 
>>>> 
>>>> 
>>> 
>>> _______________________________________________
>>> nox-dev mailing list
>>> [email protected]
>>> http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org
>> 
>> 
>> _______________________________________________
>> nox-dev mailing list
>> [email protected]
>> http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org
>> 
> 
> _______________________________________________
> nox-dev mailing list
> [email protected]
> http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org

Ali Al-Shabibi
Doctoral Student
PH-ATD
CERN - European Organization for Nuclear Research
Office: 513 R-018
[email protected]
Tel :   +41 22 767 86 46

_______________________________________________
nox-dev mailing list
[email protected]
http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org

Reply via email to