Hi Muhammad,
In our work, we also need to respond to an ARP REQUEST, we have a module
called "arpreplay", which responds to an ARP adding the MAC address of the
switch (actually, DPID +1, otherwise the package would go to the
switch-management).
Follow our code, might help:
----arpreplay----
import traceback
from nox.lib.packet import *
from nox.lib.core import *
from nox.lib.packet.ethernet import ethernet
from nox.lib.packet.arp import arp
from nox.lib.packet.ethernet import ETHER_ANY
from nox.lib.packet.packet_utils import longlong_to_octstr,
octstr_to_array, mac_to_oui
from array import *
from twisted.python import log
class arpreply(Component):
def __init__(self, ctxt):
Component.__init__(self, ctxt)
self.hwtype = arp.HW_TYPE_ETHERNET
self.prototype = arp.PROTO_TYPE_IP
self.hwsrc = ETHER_ANY
self.hwdst = ETHER_ANY
self.hwlen = 6
self.opcode = arp.REPLY
self.protolen = 4
self.protosrc = 0
self.protodst = 0
self.next = ''
def arp_input_handler(self, dp_id, inport, ofp_reason, total_frame_len,
buffer_id, packet):
arr = packet.next.arr
dst = packet.src
src = octstr_to_array(longlong_to_octstr(dp_id+1))
src.reverse()
src = src[:6]
src.reverse()
if type(dst) != type(""):
dst = dst.tostring()
if type(src) != type(""):
src = src.tostring()
buf_replay = struct.pack('!6s6sH', dst, src, packet.type)
self.next = arr[28:].tostring()
(self.hwtype, self.prototype, self.hwlen, self.protolen,self.opcode)
=\
struct.unpack('!HHBBH', arr[:8])
if self.opcode == arp.REQUEST:
self.opcode = arp.REPLY
else:
log.msg('Is not an ARP REQUEST')
return
self.hwdst = arr[8:14]
self.protodst = struct.unpack('!I',arr[14:18])[0]
self.hwsrc = src #arr[18:24]
self.protosrc = struct.unpack('!I',arr[24:28])[0]
buf_replay += struct.pack('!HHBBH', self.hwtype, self.prototype,\
self.hwlen, self.protolen,self.opcode)
if type(self.hwsrc) == type(''):
buf_replay += self.hwsrc
else:
buf_replay += self.hwsrc.tostring()
buf_replay += struct.pack('!I',self.protosrc)
if type(self.hwdst) == type(''):
buf_replay += self.hwdst
else:
buf_replay += self.hwdst.tostring()
buf_replay += struct.pack('!I',self.protodst)
buf_replay += self.next
arp_replay = array('B', buf_replay)
log.msg('Send packet for arp replay' + str(packet),
system="arpreply")
actions = [[openflow.OFPAT_OUTPUT, [0, inport]]]
self.send_openflow(dp_id, None, arp_replay, actions,
openflow.OFPP_CONTROLLER)
def install(self):
match_arp = {DL_TYPE: ethernet.ARP_TYPE}
self.register_for_packet_match(lambda
dp,inport,reason,len,bid,packet :
arpreply.arp_input_handler(self,dp,inport,reason,len,bid,packet),
0xffff, match_arp)
def getInterface(self):
return str(arpreply)
def getFactory():
class Factory:
def instance(self, ctxt):
return arpreply(ctxt)
return Factory()
----arpreplay----
On Sat, Feb 20, 2010 at 2:39 PM, Muhammad Immad Uddin
<[email protected]>wrote:
> Hi:
>
> I am trying to use nox controller to act as a proxy for a host, especially
> for icmp and arp request. I need tp have nox controller generate icmp echo
> reply packet on behalf of a host. I was able to make nox intercept a icmp
> echo request. The thing I am unable to achieve is to make nox create a icmp
> packet and send it on behalf of the host. Is there a clean API for
> generating a packet? I tried looking into the classes for icmp, ip, arp but
> I could not find any function that can encapsulate the stuff into a single
> packet.
>
> -Immad
>
>
> _______________________________________________
> nox-dev mailing list
> [email protected]
> http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org
>
>
--
Carlos Macapuna
_______________________________________________
nox-dev mailing list
[email protected]
http://noxrepo.org/mailman/listinfo/nox-dev_noxrepo.org