I am sorry for replying this thread late.

And I sent a reply only to yeffri.

At first, I successed to send an ARP reply in C++. yeffri's code 
helps me very much!

But yeffri's code can send an ARP request, so I wrote the code 
to send an ARP reply. The code is below.

To yeffri and Murphy, thank you very much !!

Kimihiko FUKAMI

=== code 1 ===

Disposition Switch::handle(const Event& e){
    const Packet_in_event& pi = assert_cast<const Packet_in_event&>(e);
    uint32_t buffer_id = pi.buffer_id;
    Flow flow(pi.in_port, *pi.get_buffer());
    stringstream out, out2;
    ipaddr ipsrc(ntohl(flow.nw_src));
    ipaddr ipdst(ntohl(flow.nw_dst));
    string tp_src;
    string tp_dst;
    ipaddr globalgwaddr(LB_IP);
    ipaddr privategwaddr(GATEWAY_IP);

    if (flow.dl_type == ethernet::ARP){
      Nonowning_buffer b(*pi.get_buffer());
      const arp_eth_header* arp = NULL;
      const eth_header* eth = b.try_pull<eth_header>();

      if (b.size() >= ARP_ETH_HEADER_LEN) {
        arp = reinterpret_cast<const 
arp_eth_header*>(b.try_pull(ARP_ETH_HEADER_\
LEN));
      }else {
        return CONTINUE;
      }

      if (arp->ar_op == arp::REQUEST){
        if (ipdst.string() == GATEWAY_IP){
          ethernetaddr senderMAC(arptable[GATEWAY_IP]);
          ethernetaddr targetMAC(flow.dl_src.string().c_str());

          sendARPReply(pi.datapath_id, pi.in_port, senderMAC, 
privategwaddr.addr\
, targetMAC, ipsrc.addr);
        }
          }

=====

sendARPReply function code is below.

======
void Switch::sendARPReply(datapathid dpid, int port, ethernetaddr senderMAC, u\
int32_t senderIP, ethernetaddr targetMAC, uint32_t targetIP)
  {
    ethernet ethPacket;
    arp arpPacket;

    ethPacket.daddr = targetMAC;
    ethPacket.saddr = senderMAC;
    ethPacket.type = ethernet::ARP;

    arpPacket.hrd = arp::ETHER;
    arpPacket.pro = ethernet::IP;
    arpPacket.hln = ethernet::PAYLOAD_MIN;  //6 for ethernet
    arpPacket.pln = sizeof(targetIP);       //4 for IPV4
    arpPacket.sha = senderMAC;
    arpPacket.sip = senderIP;
    arpPacket.tha = targetMAC;
    arpPacket.tip = targetIP;
    arpPacket.op  = arp::REPLY;

    int size = sizeof(ethernet) + sizeof(arp);
    uint8_t *data = new uint8_t[size];

    memcpy(data, &ethPacket, sizeof(ethPacket));
    memcpy(data + sizeof(ethPacket), &arpPacket, sizeof(arpPacket));
    Array_buffer buffer(data,size);  // data will be deleted automatically

    send_openflow_packet(dpid, buffer, port, OFPP_LOCAL, true);  }
 }

=== end ===

Murphy McCauley <jam...@nau.edu> wrote:

>First, I'd suggest that you install a flow to send all appropriate ARP 
>messages to the controller.
>
>Second, use the packet in event to examine the ARP request.  The data that you 
>need is all on the event object (specifically, the "buf" field of the 
>Ofp_msg_event class contains the raw packet data, which you can parse as an 
>ARP request).
>
>Third, build an ARP reply based on the request.  Send this data using one of 
>the packet sending functions (e.g., send_openflow_packet()).
>
>
>Have you considered writing this as a Python application first?
>
>
>Hope that helps.
>
>-- Murphy
>
>On Nov 30, 2011, at 12:15 AM, Kimihiko FUKAMI wrote:
>
>> Hi,Murphy!
>> 
>> Thank you for your reply!
>> 
>> I look at arp.hh source code. But, my question is not addressed.
>> 
>> I forgot to tell you the code I want to write...
>> 
>> The code is NAT program. In the NAT, the condition is that arp 
>> reply should be addressed.
>> 
>> I examined which api to send arp reply by using of Nox(zaku) in 
>> C++, and I get a hint from attached Nox sample code "switch.cc".
>> The hint is Packet_in_event...
>> 
>> Then I want to tell you how to get packet data from Packet_in_event
>> instance. Please give me a hint!
>> 
>> 
>> Murphy McCauley <jam...@nau.edu> wrote:
>> 
>>> I don't think I've ever used it, but have you taken a look at 
>>> include/netinet++/arp.hh?
>>> 
>>> -- Murphy
>>> 
>>> On Nov 25, 2011, at 1:54 AM, Kimihiko FUKAMI wrote:
>>> 
>>>> Hi,
>>>> 
>>>> Currently, I can not send an ARP Reply by using of Nox(zaku) in 
>>>> C++ code. 
>>>> 
>>>> # I can write a code to reply ARP in python. 
>>>> 
>>>> So, I want a code sample to send ARP Reply in C++.
>>>> 
>>>> Please teach me!
>>>> 
>>>> ---
>>>> E-mail: fukami.kimih...@lab.ntt.co.jp
>>>> 
>>>> _______________________________________________
>>>> nox-dev mailing list
>>>> nox-dev@noxrepo.org
>>>> http://noxrepo.org/mailman/listinfo/nox-dev
>> 
>> 
>> ---
>> 深見 公彦 (Kimihiko FUKAMI)  TEL:0422-59-2475 
>> NTT 情報流通プラットホーム研究所
>> ネットワークセキュリティプロジェクト
>> E-mail: fukami.kimih...@lab.ntt.co.jp
>> 



_______________________________________________
nox-dev mailing list
nox-dev@noxrepo.org
http://noxrepo.org/mailman/listinfo/nox-dev

Reply via email to